title: php for loop of an array
body: <p>I have an html form that passes an array into php and then does a for loop to print out values. This is the code that I have</p>
  
  <pre><code>$payloads = $_POST['topay'];
  $loadNum = $_POST['loadnum'];
  $unit = $_POST['unit'];
  $driver = $_POST['driver'];
  
  for($i=0;$i&lt;count($payloads);$i++)
      {
          echo $payloads[$i];
          echo "&lt;br&gt;";
          echo '&lt;td width="50" valign="top"&gt;'.$loadNum[$i].'&lt;/td&gt;';
          echo '&lt;td width="50" valign="top"&gt;'.$unit[$i].'&lt;/td&gt;';
          echo '&lt;td width="150" valign="top"&gt;'.$driver[$i].'&lt;/td&gt;';
      }
  </code></pre>
  
  <p>the $_POST['topay'] is a checkbox array that I pass in where only the items that are checked will come through. For example in the form that I pass to php there are multiple check boxes, and it should only pass the ones that are checked. When I do the first echo in the for loop it correctly prints out the values, but the echos within the  do not.</p>
  
  <p>Values:</p>
  
  <pre><code>$loadNum = [5,6]
  $unit = [101,103]
  driver = ["joe", "mike"]
  </code></pre>
  
  <p>When both of these checkboxes are checked, the output works correctly. When the first checkbox is checked, the output works correctly. However, if I only check the second one (6, 103, "mike"), the output still comes out for (5,101,"joe")</p>
  
  <p><strong>EDIT:</strong>
  here is the HTML code that i send to this php page:</p>
  
  <pre><code>echo '&lt;form action="statement.php" target="_blank" METHOD="post"&gt;';
  echo '&lt;td&gt;&lt;input type="checkbox" name="topay[]" value="'.$loadNumber.'" checked&gt;&lt;/td&gt;';
  echo '&lt;td width="70"&gt;&lt;input type="hidden" name="loadnum[]" value="'.$loadNumber.'" /&gt;'. $loadNumber.'&lt;/td&gt;';
  echo '&lt;td width="70"&gt;&lt;input type="hidden" name="unit[]" value="'.$unit.'" /&gt;' .$unit.'&lt;/td&gt;';
  echo '&lt;td width="150"&gt;&lt;input type="hidden" name="driver[]" value="'.$driver.'" /&gt;' .$driver.'&lt;/td&gt;';
  ?&gt;
  &lt;p&gt;&lt;input type="submit" name="sumbit" value="Create Statement" /&gt;&lt;/p&gt;
  </code></pre>