前言
在系统开发的过程中有时候需要在用户注册的时候输入邀请码,这里分享一种快速生成邀请码的方法。
/**
* 生成邀请码
* @param unitCode
*/
function create_invite_code($unitCode, $len = 3)
{
$arr = ["1", "2", "3", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
$arrLen = count($arr) - 1;
for ($i = 0; $i < $len; $i++) {
$unitCode .= $arr[mt_rand(0, $arrLen)];
}
return $unitCode;
}
例如:ANC39K