php8.5
Home/ Manual/ strings / functions/ str_shuffle

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

string

The input string.

Return Values

Returns the shuffled string.

Changelog

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

See Also

Source: reference/strings/functions/str-shuffle.xml · from the official PHP manual (php/doc-en)