Example
Randomly shuffle all characters in string:
<?php echo str_shuffle("Hello World"); ?>
Definition and usage
str_shuffle() Function Randomly shuffle all characters in the string.
Syntax
str_shuffle(string)
Parameters | Description |
string | Required. Specifies the string to be scrambled. |
Technical details
Return value: | Returns the scrambled string. |
PHP version: | 4.3.0+ |
str_shuffle(): Randomly shuffle the string order.
You can generate a different string every time by combining the str_shuffle() function and the substr() function.
The following are two examples of the str_shuffle() function:
Example 1: Randomly generate a string of 10 digits in length.
$str="QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm"; str_shuffle($str); $name=substr(str_shuffle($str),26,10); echo $name;
Running result:
bdgNIC04wF
Example 2: A 10-digit string starting with NT is generated.
$str="QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm"; $str='NT'.substr(str_shuffle($str),5,8); echo $str;
Run result:
NTZYwKiDaF
The above is the detailed content of PHP's str_shuffle() function randomly shuffles all characters in a string. For more information, please follow other related articles on the PHP Chinese website!