str_shuffle
PHP function
Edit on GitHub ✎
(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
Randomly shuffles a string
Description
str_shuffle(string $string): string
str_shuffle() shuffles a string. One permutation of all possible is created.
Cryptographically-insecure Mt19937-global-state
Parameters
stringThe input string.
Return Values
Returns the shuffled string.
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
str_shuffle() example
php
<?php
$str = 'abcdef';
$shuffled = str_shuffle($str);
// This will echo something like: bfdaec
echo $shuffled;
?>