title: Checkbox Quiz Multiple Choice
body: <p>I am in the process of setting up a quiz which can have many answers for one question. The checkboxes are stored using an array and checked against my <code>answers_bank</code> table with the <code>ab_name</code> column (where the correct answers are stored). </p>
  
  <p>All I am wanting to do is - if the answers which are checked are in the answers_bank table it echo's "correct", otherwise it echo's "incorrect" for the incorrect checked boxes.</p>
  
  <p>The way I have tried to do it doesn't work, as it compares each individual answer in the array during each iteration and returns incorrect for the other answers (as it is not equal). This image should explain the issue I am having:</p>
  
  <p><a href="https://i.stack.imgur.com/NHR3a.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NHR3a.jpg" alt="enter image description here"></a></p>
  
  <p>Here is a snippet of the code I have setup:</p>
  
  <p><strong>Returns the checkbox questions as shown in the first part of the image:</strong> </p>
  
  <pre><code>foreach ($qresults as $aresults) {
      $selected = $aresults["ab_name"];
      $ab_id = $aresults["ab_id"];
      ?&gt;
  
      &lt;input type="checkbox" name="checkbox[]"
             value="&lt;?php echo $aresults["ab_name"]; ?&gt;"&gt; &lt;?php echo $aresults["ab_name"]; ?&gt; &lt;br&gt;
  
      &lt;?php
  }
  ?&gt;
  </code></pre>
  
  <p><strong>Aims to check if the answers are correct or not</strong></p>
  
  <pre><code>foreach ($results as $row) {
  
  $qb_id = $row['qb_id'];
  $q_answer = $_POST["q$qb_id"];
  
  $sql = "SELECT * FROM answers_bank WHERE ab_qb_id = :qb_id AND ab_correct = :correct";
  $stmt = $db-&gt;prepare($sql);
  $stmt-&gt;bindValue(':qb_id', $qb_id);
  $stmt-&gt;bindValue(':correct', "correct");
  $stmt-&gt;execute();
  $qresults = $stmt-&gt;fetchAll();
  foreach ($qresults as $cresults) {
      if (is_array($q_answer)) {
          foreach ($q_answer as $checkbox) {
  
              if ($checkbox == $cresults["ab_name"]) {
                  echo "You said : " . $checkbox . " ... which is the correct answer!&lt;/br&gt;";
  
              } else if ($checkbox != $cresults["ab_name"]) {
                  echo "You said : " . $checkbox . " ... which is incorrect&lt;/br&gt;";
              }
  
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Any other solutions or corrections I can make to this? Thanks a lot!</p>