作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
如何在 PHP 中获取不重复的随机单词?帮助
最佳答案
如果您不想手动输入字母表,您可以执行以下操作:
<?php
function getRandomWord($len = 10) {
$word = array_merge(range('a', 'z'), range('A', 'Z'));
shuffle($word);
return substr(implode($word), 0, $len);
}
如果这是一个数据库 ID,我建议您执行以下操作:
function createUniqueId() {
while (1) {
$word = getRandomWord();
if (!idExists($word)) { // idExists returns true if the id is already used
return $word;
}
}
}
关于php - 如何在 PHP 中生成随机单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3329903/
我是一名优秀的程序员,十分优秀!