The shuffle() Function is a builtin function in PHP and is used to shuffle or randomize the order of the elements in an array. This function assigns new keys for the elements in the array. It will also remove any existing keys, rather than just reordering the keys and assigns numeric keys starting from zero.
Parameter: This function accepts a single parameter $array. It specifies the array we want to shuffle.
Return Value: This function returns a boolean value i.e., either True or False. It returns TRUE on success and FALSE on failure.
Note: This function will work for PHP version 4+.
Input:- array("a"=>"Ram", "b"=>"Shita", "c"=>"Geeta", "d"=>"geeksforgeeks" ) Output:- array(  => Geeta,  => Shita,  => Ram,  => geeksforgeeks ) Explanation: Here as we can see that input contain elemets in a order but in output order become shuffled.
Below programs illustrates working of shuffle() in PHP:
- When the input array is an associative array, then the shuffle() function will randomize the order of elements as well as assigns new keys to the elements starting from zero (0).
// input array contain some elements which
// need to be shuffled.
Array (  => geeksforgeeks  => Shita  => Ram  => Geeta )
When the input array is not associative then the shuffle() function will randmize the order and convert the array to an associative array with keys starting from zero (0).
// input array contain some elements
// which need to be shuffled.
Array (  => red  => geeta  => ram  => shyam  => blue )
- p5.js | shuffle() function
- D3.js | d3.shuffle() function
- Underscore.js | shuffle() with Examples
- Lodash _.shuffle() Method
- How to get the function name inside a function in PHP ?
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- PHP | imagecreatetruecolor() Function
- PHP | fpassthru( ) Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- PHP | GmagickPixel setcolor() function
- PHP | opendir() Function
- PHP | cal_to_jd() Function
- PHP | stream_get_transports() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : nidhi_biet