随机化数组元素[重复]

This question already has an answer here:

I have an array with a unknown number of elements. I'd like to randomize its elements so that each time i display it, its elements to be displayed in random order. now i do:

 foreach($photos['data'] as $photo)
{ echo $photo; }

is there any way to randomize the elements of $photos['data'] array? thanks!

</div>

You can use shuffle function:

For example:

<?php
suffle($photos['data'];
foreach ($photos['data'] as $photo) {
  echo $photo;
}
?>

use sort() function. see link for further help http://php.net/manual/en/function.sort.php think it will help you. thanks.

The shuffle() function randomizes the order of the elements in the array. More more info, refer this.

This function assigns new keys for the elements in the array. Existing keys will be removed.

This function returns TRUE on success, or FALSE on failure.

For EG :

<?php
$my_array = array("a" => "Dog", "b" => "Cat", "c" => "Horse");

shuffle($my_array);
print_r($my_array);
?>

In your case :

<?php
suffle($photos['data']);
print_r($photos['data']);
}
?>
echo $items[array_rand($items)];

array_rand() Gone through this function.It is best suitalbe option for your question