如何将生成的字母数字代码范围转换为数组


 The below code is what I have written
<?php
 $pincode="" ;
function getPinCode($length){
 $pincode = "";
 $codeAlphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 $codeAlphabet.= "0123456789";
 $max = strlen($codeAlphabet); // edited
 for ($i=0; $i < $length; $i++) {
    $pincode.= $codeAlphabet[random_int(0, $max-1)];//to output the combined code
 implode('', $pincode)// to convert the code to array
 $pincode= array()//explicitly declare $pincode var
 }
​return $pincode;
 }
for ($n=0;$n<8; $n++){
echo getPinCode(11);
echo ", ";
print_r($pincode);
}?>

//如果我运行上面的情况会产生错误 1.数组到字符串转换 2.爆炸()传递无效的参数。 如果我评论这两行,其中错误/起源于其生成8个不同的代码,而不是作为数组。

我想做的是使用PHP生成一组代码/将它们制成数组。请我到底在哪里出错。太感谢了

您可以简单地分配给$ pincode数组the Random value

for ($i=0; $i < $length; $i++) {
   $pincode[$i]= $codeAlphabet[random_int(0, $max-1)];//array of the code 
}

 implode('', $pincode)// to convert the code to array
 $pincode= array()//explicitly declare $pincode var

您没有分配爆破的返回值,然后您只是为$ pincode创建一个空数组。

相关内容

最新更新