PHP 根据整数ID,生成唯一字符串

//根据ID计算唯一邀请码
public static function createCode($Id){
static $sourceString = [
0,1,2,3,4,5,6,7,8,9,10,
'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'
];

    $num = $Id;
    $code = '';
    while($num)
    {
        $mod = $num % 36;
        $num = (int)($num / 36);
        $code = "{$sourceString[$mod]}{$code}";
    }

    //判断code的长度
    if( empty($code[4]))
        str_pad($code,5,'0',STR_PAD_LEFT);

    return $code;
}
原文地址:https://www.cnblogs.com/caohongchang/p/11730142.html