title: Insert data in db from foreach using many arrays various length
body: <p>Im trying to insert data from a form that looks like this:</p>
  
  <pre><code>&lt;input type="checkbox" name="single_color_show[]" value="1" id="1" checked&gt;
  &lt;input type="text" name="single_color_val[]" class="input-admin-val" value="0" id="1"&gt;
  &lt;input type="hidden" name="single_color_name[]" value="Vit: (NCS S0502-Y)" id="1"&gt;
  &lt;input type="hidden" name="single_color_head[]" value="colors" id="1"&gt;
  &lt;input type="hidden" name="single_color_standard[]" value="1" id="1"&gt;
  &lt;input type="hidden" name="single_color_order[]" value="1" id="1"&gt;
  &lt;input type="hidden" name="single_color[]" value="1" id="1"&gt;&lt;/td&gt;
  </code></pre>
  
  <p>and so on...</p>
  
  <p>What i want is all values to be stored in the db. This works fine as long as single_color_show is checked. But i need the data to be inserted regardless, but with a value of 0 instead of 1 so the script knows it should be hidden.</p>
  
  <p>This is my php code:</p>
  
  <pre><code>$single_color_show = $_POST['single_color_show'];
  $single_color = $_POST['single_color'];
  $single_color_name = $_POST['single_color_name'];
  $single_color_val = $_POST['single_color_val'];
  $single_color_head = $_POST['single_color_head'];
  $single_color_standard = $_POST['single_color_standard'];
  $single_color_order = $_POST['single_color_order'];
  
  foreach($single_color_order as $key =&gt; $n) {
  $s_color = "INSERT INTO product_attributes (products_id, att_name, att_head, att_val, att_standard, att_order, att_show) VALUES ('".$products_id_enkel."', '".$single_color_name[$key]."', '".$single_color_head[$key]."', '".$single_color_val[$key]."', '".$single_color_standard[$key]."', '".$single_color_order[$key]."', '".$single_color_show[$key]."');";
  $q = mysql_query($s_color) or die ('Error posting data enkeldörr färg');
  }
  </code></pre>
  
  <p>As long as i leave all choises checked it saves the data beutiful, but since i need to retrieve the data for future edit i need all the presented choices to go with the choosen attributes.</p>
  
  <p>If i check lets say 2 out of 3 choises i want the data to be stored as this</p>
  
  <pre><code>products_id, att_name, att_head, att_val, att_standard, att_order, att_show
  12           Red       Color      80          1            1          1
  12           Blue      Color      50          0            2          0
  12           Green     Color      70          0            3          1
  </code></pre>
  
  <p>This is what i get now:</p>
  
  <pre><code>products_id, att_name, att_head, att_val, att_standard, att_order, att_show
  12           Red       Color      80          1            1          1
  12           Green     Color      70          0            3          1
  </code></pre>