str_shuffle()
str_shuffle() — Randomly shuffles a string.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.3.0, 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
str_shuffle() shuffles a string. One permutation of all possible is created.
Signature
str_shuffle(string $string): string
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $string | string | The input string. |
Return value
Returns the shuffled string.
Example
A runnable snippet:
$str = 'abcdef'; $shuffled = str_shuffle($str); // This will echo something like: bfdaec echo $shuffled;
Changelog
| Version | Change |
|---|---|
| 7.1.0 | The 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 str_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.