Shuffle ()
The PHP shuffle () function randomly arranges the order of the array cells (the array is scrambled). This function assigns the new key name to the cells in the array, which removes the existing key names and not just the reordering.
Grammar:
BOOL Shuffle (array &array)
Example 1:
<?php$arr = Range (1,8);p rint_r ($arr); Echo '
'; Shuffle ($arr);p rint_r ($arr); >
Run the example output:
It is necessary to note that each time the page is refreshed, the Print_r ($arr) results after shuffle ($arr) are different. Since PHP 4.2.0, it is no longer necessary to use Srand () and other functions to seed the random number generator and the system automatically completed.
Example 2, using associative arrays:
<?php$arr = Array ("A" =>1, "B" =>2, "C" =>3, "D" =>4, "E" =>5); Shuffle ($arr);p rint_r ($arr);? >
Run the example output:
Array ([0] = 5 [1] = 2 [2] = 1 [3] = 3 [4] = 4)
Of course, the results of each refresh of the page output are not the same.
The above is a small series for everyone to bring PHP to the array to disrupt the use of shuffle functions and simple examples of all the content, I hope you support the script home ~