Matching an input value with a form field value

I’m building an online quiz, I’m having trouble counting the number of correct values though. Each question has the following HTML:

<div class="form-group">
  <label for="question <?PHP echo $question['id']; ?>"><?PHP echo $question['question']; ?></label>
  <input type="hidden" value="<?PHP echo $question['answer']; ?>" name="original_number[]">
  <input type="number" class="form-control" name="input_number[]" placeholder="<?PHP echo $question['question']; ?>" required>
</div>

There’s a hidden input which contains the actual correct answer. I think I can get away with this as the quiz is a maths test for primary school children. The questions and answers are all stored in a database so my code loops through each question and outputs the above HTML for each one.

When it comes to actually submitting the form and then checking each input against the correct answer, everything I’ve tried so far doesn’t seem to work, I’ve tried foreach looping around each question but that doesn’t seem to work.

Ideally, each correct answer needs to add +1 to a variable. If that variable matches the total number of questions once the form has been submit, the test is marked as complete (I’ve already got the code in place for this).

Here’s a couple of things I’ve tried:

foreach ($original as $key => $value) {
echo ‘<p>’.$key.'</p>’;
foreach($value as $k => $v)
{
echo ‘<p>’.$k.'</p>’;
echo ‘<p>’.$v.'</p>’;
echo ‘<hr />’;
}

^ Just outputs a list of numbers 0-12

foreach ($_POST as $key => $value) {
echo ‘<p>’.$key.'</p>’;
foreach($value as $k => $v)
{
echo ‘<p>’.$k.'</p>’;
echo ‘<p>’.$v.'</p>’;
echo ‘<hr />’;
}

This outputs 2 lists. The first list is 0-12 and then the value for original_number. The second list is also 0-12 and outputs the value for input_number.

Unless you are checking the answers with JS, there is no reason to put the answers in hidden inputs.

name your inputs to line up with the answers array and just loop over it all.