str_shuffle
PHP Manual
PHP Manual»String Функції»str_shuffle

str_shuffle

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

str_shuffleRandomly shuffles a string

Опис

function str_shuffle(string $string): 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.

Параметри

string

The 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;
?>

Прогляньте також

To Top