Home >>PHP String Functions >PHP str_shuffle() Function
PHP str_shuffle() function is used to randomly shuffle all the characters of a given input string passed as a parameter. If a number is passed, it treats the number also as a string and shuffles it. It does not make any changes in the original string but it returns a new string which is one permutation of all the possible strings created.
Syntax:
str_shuffle($string);
Parameter | Description |
---|---|
string | This is a required parameter. This parameter contains the string to be shuffled. |
Here is an example of str_shuffle() function in PHP:
<html> <body> <?php $str = "PHPTPOINT"; echo str_shuffle($str); ?> </body> </html>
Here is an another example of str_shuffle() function in PHP:
<html> <body> <?php $str = "PHPTPOINT"; echo "Shuffle string-- ".str_shuffle($str)."<br>"; echo "Original String-- ".$str."<br>"; //Original string doesn't change ?> </body> </html>