I have a 2D array called $questions[$i][$j]. The first...brackets are associated with the index $i that can be 0 to 9. The $j has values from 0 to 4. What this array simply contains is the data of 10 questions. If we have the following question, which is the 1st in a list of 10 questions (the () corresponds a radio button):
Question 1: What is the thing?
() Choice1
() Choice2 (this is the correct choice)
() Choice3
its will be stored like:
$questions[0][0] = "What is the thing?";
$questions[0][1] = "Choice1";
$questions[0][2] = "Choice1";
$questions[0][3] = "Choice1";
$questions[0][4] = 2;
where the two is the value corresponding to the right choice of the question.
Now, when the user answers all 10 questions, his answers will be stored in another 1 dimentional array called $answers[], that has 10 elements that are an ordered list of the choices he made for each 10 questions (i.e. 1 or 2 or 3 for each question according to the choice the user chose: 1st, 2nd or 3rd choice).
After that i want to see if he's answered which question right so that i could increment the variable $score for each right answer.
I made the following for loop to check each value of the $answers[] array and the 5th element in every sub-array of the 10 sub-arrays in the array $questions[][] , but it doesn't work.
CODE:
for ($i=0; $i<10; $i++)
{ if($questions[$i][4] == $answers[$i])
$score++;
}
The score stays 0 no matter how the user answers. I checked the $answers array and it seems to be storing the answers alright, but the problem seems to be in the $questions[][] array. When i place a print statement in the for loop to print $questions[$i][4], it prints NOTHING!
please help...