Ben*_*ier 14
如果您不想手动键入字母,可以执行以下操作:
<?php
function getRandomWord($len = 10) {
$word = array_merge(range('a', 'z'), range('A', 'Z'));
shuffle($word);
return substr(implode($word), 0, $len);
}
Run Code Online (Sandbox Code Playgroud)
如果这是一个数据库ID,我建议你如下:
function createUniqueId() {
while (1) {
$word = getRandomWord();
if (!idExists($word)) { // idExists returns true if the id is already used
return $word;
}
}
}
Run Code Online (Sandbox Code Playgroud)
试试这个功能
function randw($length=4){
return substr(str_shuffle("qwertyuiopasdfghjklzxcvbnm"),0,$length);
}
Run Code Online (Sandbox Code Playgroud)
$words = preg_split('//', 'abcdefghijklmnopqrstuvwxyz0123456789', -1);
shuffle($words);
foreach($words as $word) {
echo $word . '<br />';
}
Run Code Online (Sandbox Code Playgroud)
http://php.net/manual/en/function.shuffle.php