October 2005
Intermediate to advanced
372 pages
11h 35m
English
shuffle()
bool shuffle ( array &arr )The shuffle() function takes an array as its parameter, and randomizes the position of the elements in there. It takes its parameter by reference—the return value is either true or false, depending on whether it successfully randomized the array. For example:
$natural_born_killers = array("lions", "tigers", "bears", "kittens");
shuffle($natural_born_killers);One major drawback to using shuffle() is that it mangles your array keys. This is unavoidable, sadly.