I need four multiple random numbers without repeating. So i took an array for it. Can you help me where i have done wrong? I have 24 questions to come in random order, I need 4 questions per page, for this i took an array "$questions" and initially inserted 25 into it. then when ever i got a random number which is not in array, i am replacing that particular index with the random number. Where i have done wrong?
<?php
$questions = array(0);
for ($i = 0; $i < 24 ; $i++) {
$questions[$i]= ",";
}
$a="1";
$b="2";
$c="3";
$d="4";
//$a=rand(0, 23);
while(!in_array($a=rand(0, 23), $questions)) {
$replacements = array($a => $a);
$questions = array_replace($questions, $replacements);
$max = sizeof($questions);
if ($max==4) {
break;
}
echo "<br>a=".$a."<br>";
for ($i = 0; $i < 24 ; $i++) {
echo $questions[$i];
}
}
//echo "a=".$a."b=".$b."c=".$c."d=".$d;
?>