title: How to use array_intersect inside foreach in PHP, MySQL
body: <p>I'm trying to loop a table by comparing the results that I get from another table but it seems to be skipping the null index value.</p>
  
  <p>What I want to get from the result is if one of the value of $a can be found on $b, it should echo the loop that it is associated or rather the index of that array.</p>
  
  <pre><code>       &lt;ol&gt;
              &lt;?php
              $questions = db_query("SELECT * FROM tbl_questions");
              while ($quests = $questions-&gt;fetch_assoc()) {
                  $b[] = $quests['question_id'];
                  $comp = db_select("SELECT * FROM tbl_votes WHERE `user_id` = $userids");
                  foreach($comp as $compare){
                      $check[] = $compare['question_id'];
                  }
                  $a = array_intersect($b, $check);
                  if($a){
                      echo "&lt;li&gt;&lt;a class='qstyle' href='questions/".$quests['question_id'].".php'&gt;".$quests['question_title']."&lt;/a&gt;&lt;/li&gt;";
                  }
                  elseif($quests['question_live'] == 1){
                          echo "&lt;li&gt;&lt;strong&gt;&lt;a class='qstyle' href='vote_page.php?var=".$quests['question_id']."'&gt;".$quests['question_title']."&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;";
                  }
                  elseif($quests['question_live'] == 0){
                      echo "&lt;li style='color:#968c8d'&gt;".$quests['question_title']."&lt;/li&gt;";
                  }                       
              }
              ?&gt;
          &lt;/ol&gt;
  </code></pre>