title: Loop through form input arrays in php
body: <p>I'm building an app in CodeIgniter. I have an invoice form which uses jQuery to create new line items. The line items are formated as follows:</p>
  
  <pre><code>&lt;input type="text" name="invoice[new_item_attributes][][description]" class="ui-corner-all text invDesc" title="Description" /&gt;
  &lt;input type="text" name="invoice[new_item_attributes][][qty]" class="ui-corner-all text invQty" title="Qty" /&gt;
  &lt;input type="text" name="invoice[new_item_attributes][][amount]" class="ui-corner-all text invAmount" title="Amount" onChange="CalculateTotal(this.form)" /&gt;
  &lt;input type="hidden" name="invoice[new_item_attributes][][rowTotal]" class="row-total-input" /&gt;
  </code></pre>
  
  <p>What I can't work out is how can I loop through multiple line items to store then in a DB called line items. </p>
  
  <p>At the moment i have </p>
  
  <pre><code>foreach ( $_POST['invoice'] as $key =&gt; $value)
      {
          $data = array(
              'description'   =&gt;  $value;
                      );
      }   
  </code></pre>
  
  <p>But I know that can't be write because I need to somehow reference the <em>invoice[new_item_attributes][][description]</em> to store it in description etc...</p>
  
  <p>Any help would be greatly appreciated.</p>