title: How to create an array of a group of items inside an HTML form
body: <p>I'm trying to create a form along the lines of the following (I am aware that this is not valid HTML, but it hopefully illustrates what and why I am trying to do this):</p>
  
  <pre><code>&lt;form method="post" action="test.php"&gt;
      &lt;input type="text" name="teamName"&gt;
      &lt;br /&gt;Players:
      &lt;grouping name="players[]"&gt;
          &lt;input type="text" name="firstName"&gt;&lt;br /&gt;
          &lt;input type="text" name="lastName"&gt;&lt;br /&gt;
      &lt;/grouping&gt;
      &lt;input type="submit" value="submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Through javascript, I would then add the grouping element as many times as needed. When the form is submitted, I could then access the items in the grouping element as follows:</p>
  
  <pre><code>foreach ($players as $player) {
      $fName = $player-&gt;firstName;
      $lName = $player-&gt;lastName;
  }
  </code></pre>
  
  <p>That is, before I start, I don't know how many players will be on the team, but I know what a player looks like. I want to keep this all on one screen, so that the user can add players to their team on one page, and I want to be able to add the grouping of fields as a group. However, I would also like that grouping to be stored as an array, instead of doing something like:</p>
  
  <pre><code>&lt;form method="post" action="test.php"&gt;
      &lt;input type="text" name="teamName"&gt;
      &lt;br /&gt;Players:
      &lt;input type="text" name="firstName[]"&gt;&lt;br /&gt;
      &lt;input type="text" name="lastName[]"&gt;&lt;br /&gt;
      &lt;input type="submit" value="submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>which would mean that I could iterate through the individual elements in the grouping, but not through the grouping as a whole.</p>
  
  <p>Any ideas how I might accomplish this?</p>