用php生成一个可选位数的数字和英文随机码
下面是用php生成一个可选位数的数字和英文随机码的相关内容,文章教程主要讲述与位数 数字 英文 随机码 相关的一些技术与知识,获取更多最新教程,下面是教程讲解:
用php生成一个可选位数的数字和英文随机码实例代码,下面是代码实例。https://www.hfxskyyj.com/
<?php
echo coding(6);
function coding($num){
$str_arr = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9');
$rand_s = array_rand($str_arr,$num);
$code_s = '';
if(is_array($rand_s)){
foreach($rand_s as $v){
$code_s .= $str_arr[$v];
}
return $code_s;
}else{
return $str_arr['rand_s'];
}
}
?>