shuffle()

shuffle() — Shuffle an array.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

This function shuffles (randomizes the order of the elements in) an array.

Signature

shuffle(array &$array): true

Parameters

ParameterTypeWhat it takes
&$arrayarrayThe array.

Return value

Always returns true.

Example

A runnable snippet:

$numbers = range(1, 20); shuffle($numbers); foreach ($numbers as $number) { echo "$number "; }

Changelog

VersionChange
7.1.0The internal randomization algorithm has been changed to use the Mersenne Twister Random Number Generator instead of the libc rand function.

All PHP 8.5 built-in functions

Reference card built from the PHP manual page shuffle() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.