gpt4 book ai didi

php - 如何在 PHP 中生成随机单词?

转载 作者:可可西里 更新时间:2023-11-01 12:26:48 25 4
gpt4 key购买 nike

如何在 PHP 中获取不重复的随机单词?帮助

最佳答案

如果您不想手动输入字母表,您可以执行以下操作:

<?php
function getRandomWord($len = 10) {
$word = array_merge(range('a', 'z'), range('A', 'Z'));
shuffle($word);
return substr(implode($word), 0, $len);
}

codepad example

如果这是一个数据库 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com