title: php for loop to compare values in an array
body: <p>I have a for loop that checks numbers stored in a database.
  The data is stored as a string and then split in php.
  The code below should only return the amount of stock for that that size. It looks as though it should work.
  The data is stored in the database like this:</p>
  
  <p>size,quantity_*_size,quantity: and so on</p>
  
  <p>I start by splitting the array:</p>
  
  <pre><code>$result = mysql_fetch_assoc($get);
  $sizes = explode('_*_',$result['sizes']);
  </code></pre>
  
  <p>Pretty straight foreward, this is then lopped through and split</p>
  
  <pre><code>for($x = 0; $x &lt; count($sizes); $x){
      $current_size = explode(',',$sizes[$x]);
      if($size === (int)$current_size[1]){
          $stock = $current_size[1];
             //do something with matched data
             $x = count($sizes);
          }else{
             $x++;
          }
  }
  </code></pre>
  
  <p>But it doesn't ever match the data.
  I've been at this for hours now and I've got nothing.
  This is the whole thing:</p>
  
  <pre><code>$result = mysql_fetch_assoc($get);
      $sizes = explode('_*_',$result['sizes']);
      //check stock of each size
      $size = (int)substr($size,6,2); //origal string from POST Size :x
      $stock = 0;
          for($x = 0; $x &lt; count($sizes); $x){
          $current_size = explode(',',$sizes[$x]);
          echo $size.'='.$current_size[1].'.';
          if($size === (int)$current_size[1]){
              $stock = $current_size[1];
              echo 'found it';
              $x = count($sizes);
          }else{
              $x++;
          }
          echo $size.'='.$current_size[1].'    ';
      }
      echo $stock;
  </code></pre>
  
  <p>If it helps this is the data from the database as its stored:
  4,10_*<em>6,14</em>*_8,0_*<em>10,3</em>*_12,0_*_14,2</p>
  
  <p>data is formated to match the explode function but its changed in here.</p>