Name
shuffle()
Synopsis
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.
Get PHP in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.