php8.5
Home/ Manual/ array / functions/ shuffle

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

array

The array.

Return Values

Always

Changelog

VersionDescription
7.1.0The 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 ";
}
?>

Notes No-key-association Reset-index

See Also

Source: reference/array/functions/shuffle.xml · from the official PHP manual (php/doc-en)