//输入当前的用户编号自增长的id function getInviteCode($userId){ $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123
//输入当前的用户编号自增长的id function getInviteCode($userId){ $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $num = strlen($chars); $str = ''; while ($userId > 0) { $mod = $userId % $num; $userId = ($userId - $mod) / $num; $str = $chars[$mod] . $str; } $cd=$this->createNonceStr(6 - strlen($str)); // 不足用随机字符串补充,10表示邀请码邀请10位 $str = str_pad($str, 6, $cd, STR_PAD_LEFT); return $str;}function createNonceStr($length = 16){ $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $str = ''; for ($i = 0; $i < $length; $i++) { $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); } return $str;}
来源地址:https://blog.csdn.net/qq_25255469/article/details/129999293
--结束END--
本文标题: Php中生成6位无规律、唯一、不重复的邀请码
本文链接: https://lsjlt.com/news/411186.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0