title: How can I use the array-format input field names in my HTML form that posts to PHP?
body: <p>I understand the basics of using the array-formatted HTML input names.  If I had a form with a variable number of 'item' inputs I might do something like this for each of them:</p>
  
  <pre><code>&lt;input name='item[]' type='text' /&gt;
  </code></pre>
  
  <p>And when I retrieve the items from the $_POST array I could iterate over them like so:</p>
  
  <pre><code>$items = $_POST['item'];
  foreach($items as $item) {
  }
  </code></pre>
  
  <p>But my question is slightly more complicated.  I have a form where users can click a button "add one" and a new row will appear at the bottom number of the form.  Each new row contains a 'name' and 'description' input.</p>
  
  <p>So initially I thought I would do this:</p>
  
  <pre><code>&lt;input name='item[name][]' type='text' /&gt;
  &lt;input name='item[description][]' type='text' /&gt;
  </code></pre>
  
  <p>And then iterate over them like so:</p>
  
  <pre><code>$items = $_POST['item'];
  foreach($items as $item) {
    print $item['name'] . ' ' . $item['description'];
  }
  </code></pre>
  
  <p>But instead of working as I hoped, it instead structures the 'item' array such that I would access the first item name as <code>$item['name'][0]</code> rather than as <code>$item[0]['name']</code>.</p>
  
  <p>So then I flipped it so that my inputs were named as such:</p>
  
  <pre><code>&lt;input name='item[][name]' type='text' /&gt;
  &lt;input name='item[][description]' type='text' /&gt;
  </code></pre>
  
  <p>But this resulted in a separate 'item' for each 'name' and for each 'description' rather than grouping each pair in a single 'item'.</p>
  
  <p>I really dislike having arrays of 'name' and separate array of 'description'.  I would prefer arrays of 'item' with each array containing a 'name' and a 'description' field.  Is there any way to accomplish this without generating the an index in my javascript?  Since people can add and remove these dynamically it's very difficult for my javascript to calculate the appropriate index for the next item.  Is there no way to do this generically?</p>