PHP shuffle() Function

The shuffle() function is used to randomize the order of the elements in the array. The function assigns new keys to the elements in array.

Note: The function uses a pseudo-random number generator that is not suitable for cryptographic purposes.

Returns TRUE on success or FALSE on failure

ParameterDescription
arrayRequired. Specifies the array to use

Syntax

shuffle(array) 

Example

$people = array("James","Lachlan","Cooper");
shuffle($people);
print_r($people);

Output

Array ( [0] => Cooper [1] => Lachlan [2] => James )

Leave a Reply

Your email address will not be published. Required fields are marked *