PHP Function Reference

PHP str_shuffle() Function



The PHP str_shuffle() function returns the string with randomly shuffled all characters of the specified string.

Syntax

str_shuffle(string)

Parameters

string Required. Specify the string to randomly shuffle

Return Value

Returns the randomly shuffled version of the specified string.

Example:

In the example below, str_shuffle() function returns a string with randomly shuffled all characters of the given string.

<?php
$MyString = "HELLO WORLD";
$NewString = str_shuffle($MyString);

echo "Original string is: ".$MyString."\n";
echo "Shuffled string is: ".$NewString."\n";
?>

The output of the above code will be:

Original string is: HELLO WORLD
Shuffled string is: OHLWLR DOLE

❮ PHP String Reference