1 <?php 2 3 $arr1 = array_merge(range('A','Z'),range(0,9),range('a','z')); //生成数组且合并为arr1 4 shuffle($arr1); //打乱顺序 5 $arr2 = array_rand($arr1,4); //arr1随机取四位生成新数组 6 $str = ""; 7 print_r($arr2); 8 echo "<br/>"; 9 foreach($arr2 as $index){ //根据arr2生成四位字符串 10 $str .= $arr1[$index]; 11 } 12 echo $str; //输出字符串 13 // print_r($arr1);
标签:index,随机数,arr2,str,arr1,php,四位 From: https://www.cnblogs.com/hnqyliu/p/16589640.html