title: Show checkbox values from database in PHP
body: <p>In Database I have a column <strong>'language'</strong> which have values <strong>English</strong>, <strong>Arabic</strong>, <strong>Urdu</strong> respectively. Now, I am getting these values and show these values in checkboxes for update purposes. I have to check the checkbox if it matches the value with database value and then make it checked otherwise unchecked. But I am getting the wrong results.. Below code is working fine for just 1st value returned from database which is <strong>'English'</strong> in my case and it is checked if it matches the database value but code is not working for other values and it remains unchecked even if it matches the database value.. Please help me..</p>
  
  <p>Below is my code and image...</p>
  
  <p><a href="https://i.stack.imgur.com/gt9tx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gt9tx.png" alt="See Image For Error"></a></p>
  
  <p><strong>PHP:-</strong></p>
  
  <pre><code>$lang = $pdo-&gt;prepare("SELECT `language` FROM admin_panel_languages WHERE user_id=:user_id");
  $lang-&gt;execute(array(":user_id"=&gt;$user_id));
  $lang_spoken=$lang-&gt;fetchAll(PDO::FETCH_ASSOC);
  print_r($lang_spoken);
  
  foreach($lang_spoken as $lang){
  
  if($lang['language']=="English"){
  
  ?&gt;
  
  &lt;label class="col-md-4"&gt;
  &lt;input type="checkbox" value="English" name="language[]" id='checkboxes' checked/&gt; English &lt;/label&gt;
  
  &lt;?php } else{ ?&gt;
  
  &lt;label class="col-md-4"&gt;
  &lt;input type="checkbox" value="English" name="language[]" id='checkboxes'/&gt; English &lt;/label&gt;
  
  &lt;?php } break; } ?&gt;
  
  foreach($lang_spoken as $lang){
  
  if($lang['language']=="Hindi"){
  
  ?&gt;
  
  &lt;label class="col-md-4"&gt;
  &lt;input type="checkbox" value="Hindi" name="language[]" id='checkboxes' checked/&gt; Hindi&lt;/label&gt;
  
  &lt;?php } else{ ?&gt;
  
  &lt;label class="col-md-4"&gt;
  &lt;input type="checkbox" value="Hindi" name="language[]" id='checkboxes'/&gt; Hindi&lt;/label&gt;
  
  &lt;?php } break; } ?&gt;
  </code></pre>
  
  <p>Now, I have <strong>English</strong>,<strong>Hindi</strong>,<strong>Arabic</strong> in Array. But my code is only working for 1st element of array which is <strong>English</strong> and make is checked but for the rest of values it remain unchecked even if statement is matched. It is always going to else statement for rest of values.. Please tell me where is the problem. Thanks in advance..</p>