PHP will disrupt the shuffle function usage and simple instances, disrupt shuffle
Shuffle ()
The PHP shuffle () function randomly sorts the order of array units (disrupt the array ). This function assigns a new key name to the Unit in the array. This will delete the original key name, not just the reorder.
Syntax:
Bool shuffle (array & array)
Example 1:
<?php$arr = range(1,8);print_r($arr);echo '<br />';shuffle($arr);print_r($arr);?>
Run the sample output:
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 ) Array ( [0] => 6 [1] => 1 [2] => 3 [3] => 2 [4] => 5 [5] => 7 [6] => 8 [7] => 4 )
Note that the result of print_r ($ arr) after shuffle ($ arr) is different each time you refresh the page. Since PHP 4.2.0, the system does not need to use functions such as srand () to seeding the random number generator.
Example 2: Associate an array:
<?php$arr = array("a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5);shuffle($arr);print_r($arr);?>
Run the sample output:
Array ([0] => 5 [1] => 2 [2] => 1 [3] => 3 [4] => 4)
Of course, the output results of each page refresh are different.
The above is the usage of shuffle function and simple instance of PHP, which will disrupt the array. I hope you can support more help ~