What is the str_shuffle() method in PHP?

The str_shuffle method can be used to shuffle a string randomlyRandomly reorder the content of the string..

Syntax


str_shuffle(string $string): string

Return value

This method returns the shuffled string as a new string. The original string remains unchanged.

Code

<?php
$str = '123456';
$shuffled = str_shuffle($str);
echo $shuffled."\n";
$shuffled = str_shuffle($str);
echo $shuffled."\n";
$shuffled = str_shuffle($str);
echo $shuffled."\n";
?>

Explanation

In the code above, we have created a string and shuffled the contents of the string using the str_shuffe method.

Free Resources