shuffle
Disrupt the array
shuffle()
function rearranges the elements in the array in a random order.
This function assigns new key names to elements in the array. Already key names will be deleted (see Example 2 below).
Reorder the elements in the array in a random order:
<?php $my_array = array ( "red" , "green" , "blue" , "yellow" , "purple" ) ; shuffle ( $my_array ) ; print_r ( $my_array ) ; ?>
Try it yourself
Rearrange elements in the array in a random order:
<?php $my_array = array ( "a" => "red" , "b" => "green" , "c" => "blue" , "d" => "yellow" , "e" => "purple" ) ; shuffle ( $my_array ) ; print_r ( $my_array ) ; ?>
Try it yourself
shuffle ( array )
parameter | describe |
---|---|
array | Required. Specifies the array to be used. |