php怎么生成6位的不重复的字符串
2个回答
2018-07-30 · 百度认证:河北灵动电子商务有限公司
灵动电商
河北灵动电子商务有限公司-高端网站建设公司.主要从事网站建设,SEO优化,平面设计,微信营销,微信二次开发,团队成员自2004年开始从事网站建设相关服务,拥有丰富的设计和技术经验,专为中小企业提供网站建设
向TA提问
关注
展开全部
给你一个我自己写的function吧。
length:生成的字符串长度,默认是12
type接收参数三种,默认是all:letter:大小写字母 int:全数字 all:字母加数字
public function len($length=12,$type="all"){
$int_arr = array("0","1","2","3","4","5","6","7","8","9","0");
$letter_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");
$len_data = array();
for($i=0;$i<$length;$i++){
switch($type){
case "int":
$rand = $int_arr;
break;
case "letter":
$rand = $letter_arr;
break;
default:
$rand = array_merge($int_arr,$letter_arr);
break;
}
$len_data[] = $rand[rand(0,count($rand)-1)];
}
return implode("",$len_data);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询