(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
str_shuffle — Randomly shuffles a string
str_shuffle() shuffles a string. One permutation of all possible is created.
Ця функція не генерує криптографічно безпечні значення, тож не повинна використовуватись для криптографічних цілей чи тих, що вимагають використання непередбачуваних значень.
Якщо потрібна криптографічно безпечна випадковість, можна використати Random\Randomizer разом з рушієм Random\Engine\Secure. Для простих випадків є функції random_int() і random_bytes(), які забезпечують зручний і безпечний API до системного CSPRNG.
This function uses the global Mt19937 (“Mersenne Twister”) instance as the source of randomness and thus shares its state with all other functions using the global Mt19937. Using any of these functions advances the sequence for all the other functions, regardless of scope.
Generating repeatable sequences by seeding mt_srand() or srand() with a known value will also yield repeatable output from this function.
Prefer using Random\Randomizer methods in all newly written code.
stringThe input string.
Returns the shuffled string.
| Версія | Опис |
|---|---|
| 7.1.0 | The internal randomization algorithm has been changed to use the » Mersenne Twister Random Number Generator instead of the libc rand function. |
Приклад #1 str_shuffle() example
<?php
$str = 'abcdef';
$shuffled = str_shuffle($str);
// This will echo something like: bfdaec
echo $shuffled;
?>