shuffle
PHP function
Edit on GitHub ✎
(PHP 4, PHP 5, PHP 7, PHP 8)
Shuffle an array
Description
shuffle(array $array): true
This function shuffles (randomizes the order of the elements in) an array.
Cryptographically-insecure Mt19937-global-state
Parameters
arrayThe array.
Return Values
Always
Changelog
| Version | Description |
|---|---|
| 7.1.0 | The internal randomization algorithm has been changed to use the Mersenne Twister Random Number Generator instead of the libc rand function. |
Examples
shuffle() example
php
<?php
$numbers = range(1, 20);
shuffle($numbers);
foreach ($numbers as $number) {
echo "$number ";
}
?>