I have a php file that gets a list of questions from a third party. It then generates questions depending on the question type. How to I extract values of name = $i and pass them to an array?
I think the problem we are having is populating all the radio buttons, since the value is $i it changes for each question.
$max = sizeof($questions);
for($i=0; $i<$max; $i++){
$max2 = sizeof($questions[$i]);
$stop = ($max2-2);
//post to xyz
echo "<form method = 'POST' action = 'xyz.php'>";
// multiple choice
if($questions[$i][0]==1)
{
echo $questions[$i][1];
echo("<br>");
echo "<input type='radio' name= '$i' value = '$questions[$i][1]'>";
echo $questions[$i][2];
echo("<br>");
echo "<input type='radio' name= '$i' value = '$questions[$i][2]'>";
echo $questions[$i][3];
echo("<br>");
echo "<input type='radio' name= '$i' value = '$questions[$i][3]'>";
echo $questions[$i][4];
echo("<br>");
echo "<input type='radio' name= '$i' value = '$questions[$i][4]'>";
echo $questions[$i][5];
echo("<br>");
}
// true or false
else if($questions[$i][0]==2)
{
echo $questions[$i][1];
echo("<br>");
if($questions[$i][2] == "true"){
echo "<input type='radio' name= '$i' value = '$questions[$i][2]'>";
echo $questions[$i][2];
echo("<br>");
echo "<input type='radio' name= '$i' value = '$questions[$i][2]'>";
echo "false";
echo("<br>");
}
else if($questions[$i][2] == "false"){
echo "<input type='radio' name= '$i' value = '$questions[$i][2]'>";
echo "true";
echo("<br>");
echo "<input type='radio' name= '$i' value = '$questions[$i][2]'>";
echo $questions[$i][2];
echo("<br>");
}
}
// fill in the blank
else if($questions[$i][0]==3)
{
echo $questions[$i][1];
echo("<br>");
echo "<input type = 'text' name ='$i'>";
}
//open ended
else if($questions[$i][0]==4)
{
echo $questions[$i][1];
echo("<br>");
echo "<input type = 'text' name ='$i'>";
}
for($k=0; $k<$max2; $k++){
if($k != $stop){
//echo($questions[$i][$k]);
echo("<br>");
}
echo"<br>";
}
}
echo "<input type='hidden' value= '$max' name= 'max'>";
echo "<input type='submit' value= 'Submit Quiz'>";
echo "</form>";
Any help is appreciated!