PHP shuffle() function rearranges the elements in the array in random order.
php shuffle() function syntax
Function: Reorder the elements in the array in random order:
Syntax:
shuffle(array)
Parameters:
array required. Specifies the array to use.
Description: Return TRUE if successful, and FALSE if failed.
php shuffle() function example 1
<?php $a = array("class" => "php中文网","name" => "西门","job" => "讲师"); shuffle($a); print_r($a); ?>
Output:
Array ( [0] => 西门 [1] => php中文网 [2] => 讲师 )
php shuffle() function example 2
<?php $my_array = array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow","e"=>"purple"); shuffle($my_array); print_r($my_array); ?>
Output:
Array ( [0] => yellow [1] => green [2] => red [3] => purple [4] => blue )
This article is an introduction to the PHP shuffle function. I hope it will be helpful to friends in need!
The above is the detailed content of How to use shuffle function. For more information, please follow other related articles on the PHP Chinese website!