PHP Array shuffle() Function
Last Updated : 17 Mar 2025
The PHP shuffle( ) function is used to randomize the order of the elements in the array. The function assigns new keys to the elements in an array. This function introduced in PHP 4.0.
Syntax
Parameter
| Parameter | Description | Is compulsory |
|---|---|---|
| array | Specifies the array to use. | compulsory |
Returns
The shuffle( ) function returns true on success or false on failure.
Example 1
Output- Every time output is random
Array
(
[0] => networking
[1] =>dbms
[2] =>os
[3] => compiler
[4] => java
)
Example 2
Output- Every time output is random
(
[0] =>bangalore
[1] =>hyderabad
[2] =>kolkata
)
Example 3
Output- Every time output is random
Array
(
[0] => apple
[1] => banana
[2] => mango
)
Example 4
Output- Every time output is random
Array
(
[0] => 4
[1] => 5
[2] => 3
[3] => 2
[4] => 1
)
Next TopicPhp-array-sizeof-function