时间:2021-07-01 10:21:17 帮助过:10人阅读
function sc() { $ar = array(); for ($i = 0; $i < 4; $i ++) { $r = rand(0, 9); while(in_array($r, $ar)) $r = rand(0, 9); array_push($ar, $r); } return implode('', $ar); } echo sc();
------解决方案--------------------
$arr = Array('0','1','2','3','4','5','6','7','8','9');//定义数组 shuffle($arr);//打乱元素顺序 $rand = array_slice($arr,0,4);//取前四个元素 $result=implode('',$rand);//转成字符串 echo $result;