PHP 随机字符

随机字符生成

function randStr($length=4,$type="1"){
        $array = array(
            '1' => '0123456789',
            '2' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
            '3' => '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',
        );
        $string = $array[$type];
        $count = strlen($string)-1;
        $rand = '';
        for ($i = 0; $i < $length; $i++) {
            $rand .= $string[mt_rand(0, $count)];
        }
        return $rand;
    }
原文地址:https://www.cnblogs.com/bluealine/p/11040889.html