纵有疾风起
人生不言弃

php 随机生成一组字符串

// 随机生成一组字符串
function build_count_rand($number, $length = 4, $mode = 1) {
if ($mode == 1 && $length < strlen($number)) {
//不足以生成一定数量的不重复数字
return false;
}
$rand = array();
for ($i = 0; $i < $number; $i++) {
$rand[] = rand_string($length, $mode);
}
$unqiue = array_unique($rand);
if (count($unqiue) == count($rand)) {
return $rand;
}
$count = count($rand) – count($unqiue);
for ($i = 0; $i < $count * 3; $i++) {
$rand[] = rand_string($length, $mode);
}
$rand = array_slice(array_unique($rand), 0, $number);
return $rand;
}

未经允许不得转载:起风网 » php 随机生成一组字符串
分享到: 生成海报

评论 抢沙发

评论前必须登录!

立即登录