Shuffle ()
The PHP shuffle () function randomly arranges the order of array cells (the array is scrambled). This function assigns a new key name to the cell in the array, which deletes the original key name and not just the reordering.
Grammar:
BOOL Shuffle (array &array)
Example 1:
<?php
$arr = range (1,8);
Print_r ($arr);
echo ' <br/> ';
Shuffle ($arr);
Print_r ($arr);
? >
Run the example output:
Array ([0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8)
It should be explained that each time the page is refreshed, the results of the Print_r ($arr) Shuffle ($arr) are different. And since PHP 4.2.0, also no longer need to use Srand () and other functions to the random number generator seeding and the system automatically completed.
Example 2, using an associative array:
<?php
$arr = Array ("A" =>1, "B" =>2, "C" =>3, "D" =>4, "E" =>5);
Shuffle ($arr);
Print_r ($arr);
? >
Run the example output:
Array ([0] => 5 [1] => 2 [2] => 1 [3] => 3 [4] => 4)
Of course, the results of each refresh page output are not the same.
The above is a small series for everyone to bring PHP to disrupt the use of shuffle functions and simple examples of all the content, I hope that we support cloud-Habitat Community ~