title: If Statement shows only once in foreach loop
body: <p>i have a question regarding a foreach loop in PHP.
  For some reason i seem to only get the last line echo'ed back this way and i am lost in where this problem lies. Whenever i check $onderdeeltje[1] and $selectedmodel in an echo inside the foreach loop and outside the IF statement it pastes them all out perfectly without any problems. It also shows that they are equal and the same and should react on the IF statement.. As soon as i compare the two inside IF statement it shows me only the last one. Whenever i remove the checkbox echo and replace it with anything such as echo "test"; it also shows me test only once. Could anybody shed some light on this? I have multiple (2 + this one) foreach loops like this in the same page that work perfectly but only this one seems to bug.</p>
  
  <pre><code>echo "&lt;form method='post' action='formpie.php'&gt;";
  
  $onderdelen = file("onderdelen.txt");
  
  foreach ($onderdelen as $onderdeel) 
  {
      $onderdeeltje = explode(",", $onderdeel);
  
      if ($onderdeeltje[1] == $selectedmodel)
      {
          echo "&lt;input type='checkbox' name='check_list[]' value='$onderdeeltje[0]'&gt;$onderdeeltje[0]&lt;br&gt;";
      }
  }
  
  echo "&lt;/form&gt;";
  </code></pre>
  
  <p>$selectedmodel will be: iPhone 3G and the text list is this:</p>
  
  <pre><code>Reparatie touchscreen €41.50,iPhone 3G
  Reparatie Wi-Fi-antenne €50.00,iPhone 3G
  Reparatie trilmodule €40.00,iPhone 3G
  Reparatie sim slot €70.50,iPhone 3G
  Reparatie oorluidspreker €46.00,iPhone 3G
  </code></pre>
  
  <p>It only shows: Reparatie oorluidspreker €46.00 as a checkbox.</p>
  
  <p>Please help me out! :) Thanks in advance!</p>
  
  <h2>-------------------------------------------------------------</h2>
  
  <p><strong>How to solve:</strong></p>
  
  <p>It seems that there can be hidden spaces in the ouput that are not visible if these are pasted per line with things like <code>&lt;br&gt;</code> or in my case a list of repeated form checkbox values.</p>
  
  <p>To fix this you simply have to trim the value before or inside the IF equal statement like so:</p>
  
  <pre><code>foreach ($onderdelen as $onderdeel) 
  {
      $onderdeeltje = explode(",", $onderdeel);
  
      if (trim($onderdeeltje[1]) == $selectedmodel)
      {
          echo "&lt;input type='checkbox' name='check_list[]' value='$onderdeeltje[0]'&gt;$onderdeeltje[0]&lt;br&gt;";
      }
  }
  </code></pre>
  
  <p><em><strong>Solved thanks to support from ZombieSpy.</em></strong></p>