最新消息:本站所有跳转向bbs.ykit.cn的附件将全面停止,附件已转移到https://www.qingsj.com

php怎么生成6位的不重复的字符串

PHP 有客 624浏览 0评论
给你一个我自己写的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);
}

转载请注明:有客帮 » php怎么生成6位的不重复的字符串

发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址