php產生不重複隨機字串的方法:1、使用時間戳記作為原始字串,再隨機產生五個字元隨機插入任意位置,產生新的字串,程式碼為【$position=rand ()%strlen($chars)】;2、使用【array_slice】函數隨機抽取。
php產生不重複隨機字串的方法:
1、使用時間戳記作為原始字串,再隨機產生五個字符隨機插入任意位置,產生新的字串,保證不重複
function rand($len) { $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'; $string=time(); for(;$len>=1;$len--) { $position=rand()%strlen($chars); $position2=rand()%strlen($string); $string=substr_replace($string,substr($chars,$position,1),$position2,0); } return $string; }
2、使用array_slice()函數隨機抽取
相關學習推薦:php程式設計#(影片)
以上是php如何產生不重複隨機字串的詳細內容。更多資訊請關注PHP中文網其他相關文章!