【PHP原生】生成随机字符串或数字
1、生成3位随机字符串
<?php
$str = randStr(3);
echo $str;
function randStr($i)
{
    $str = "abcdefghijklmnopqrstuvwxyz0123456789";
    $finalStr = "";
    for ($j = 0; $j < $i; $j++) {
        $finalStr .= substr($str, rand(0, 37), 1);
    }
    return $finalStr;
}
2、生成随机数
<?php
function generate_code($length = 6)
{
    return rand(pow(10, $length - 1), pow(10, $length) - 1);
}
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号