This function acts on a string in a similar way that shuffle() acts on an array. With shuffle(), though, the original array is affected. With str_shuffle, the original string is left as it was and the function returns you a new string with the characters in a random order.

It is possible for str_shuffle() to return the original string as that is one possible arrangement of its characters. If you absolutely need to have a different string, be sure to check for that possibility.

$str = "Monkey";
$newStr1 = str_shuffle($str);
$newStr2 = str_shuffle($str);
 
echo $str;     // Monkey
echo $newStr1; // okMnye
echo $newStr2; // eyknMo