Problem in searching through a 2D array - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Problem in searching through a 2D array

adeydasadeydas Posts: 43Member

I am trying to make an online examination script in PHP and am stuck at the results page.
The actual answers here are stored in a 2D array called 'ans' in the format:

Say for question 1 the answers are options 2 and 4, then it would be stored as

12 14

If for the second question the answers are option 1 ,3 and 4 then

21 23 24

So the whole array would look like:

12 14
21 23 24

The options are check boxes with ID's and names similar to the way it is stored in the array.

I am using the following snippet of code to check through the answers:

for($i=1; $i<=$noq2d; $i++)
for($j=1; $j<7; $j++)

if($_POST[$z] && $nomore==false && in_array($z,$ans[$i]))


echo('Total: '.$tot.'<br>
echo('Number of correct answers: '.$cq);

However, it is giving 0 as the result under any and every situation. The full code of the result page is here:

Any help will be highly appreciated!


Sign In or Register to comment.