title: HTML/PHP - Form - Input as array
body: <p>I got a form like this</p>
  <pre class="lang-html prettyprint-override"><code>&lt;form&gt;
      &lt;input type=&quot;text&quot; class=&quot;form-control&quot; placeholder=&quot;Titel&quot; name=&quot;levels[level]&quot;&gt;
      &lt;input type=&quot;text&quot; class=&quot;form-control&quot; placeholder=&quot;Titel&quot; name=&quot;levels[build_time]&quot;&gt;
  
      &lt;input type=&quot;text&quot; class=&quot;form-control&quot; placeholder=&quot;Titel&quot; name=&quot;levels[level]&quot;&gt;
      &lt;input type=&quot;text&quot; class=&quot;form-control&quot; placeholder=&quot;Titel&quot; name=&quot;levels[build_time]&quot;&gt;
  &lt;/form&gt;
  </code></pre>
  <p>I'd like to have as $_POST output an array like:</p>
  <pre class="lang-none prettyprint-override"><code>Array (
    [1] =&gt; Array ( [level] =&gt; 1 [build_time] =&gt; 123 )
    [2] =&gt; Array ( [level] =&gt; 2 [build_time] =&gt; 456 )
  )
  </code></pre>
  <p>I know I could do something like name=&quot;levels[1][build_time]&quot; and so on, but since these elements get added dynamically, it would be hard to add an index. Is there another way?</p>
  <hr/>
  <p>As suggested, I changed my form. I also included my whole HTML now, because I think I'm missing something here. My HTML now:</p>
  <pre class="lang-html prettyprint-override"><code>&lt;div class=&quot;form-group&quot;&gt;
    &lt;label class=&quot;col-md-2&quot;&gt;Name(z.B. 1)&lt;/label&gt;
    &lt;div class=&quot;col-md-10&quot;&gt;
      &lt;input type=&quot;text&quot; class=&quot;form-control&quot; placeholder=&quot;Titel&quot; name=&quot;levels[][level]&quot;&gt;
    &lt;/div&gt;
  
    &lt;label class=&quot;col-md-2&quot;&gt;Bauzeit(In Sekunden)&lt;/label&gt;
    &lt;div class=&quot;col-md-10&quot;&gt;
      &lt;input type=&quot;text&quot; class=&quot;form-control&quot; placeholder=&quot;Titel&quot; name=&quot;levels[][build_time]&quot;&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div class=&quot;form-group&quot;&gt;
    &lt;label class=&quot;col-md-2&quot;&gt;Name(z.B. 1)&lt;/label&gt;
    &lt;div class=&quot;col-md-10&quot;&gt;
      &lt;input type=&quot;text&quot; class=&quot;form-control&quot; placeholder=&quot;Titel&quot; name=&quot;levels[][level]&quot;&gt;
    &lt;/div&gt;
  
    &lt;label class=&quot;col-md-2&quot;&gt;Bauzeit(In Sekunden)&lt;/label&gt;
    &lt;div class=&quot;col-md-10&quot;&gt;
      &lt;input type=&quot;text&quot; class=&quot;form-control&quot; placeholder=&quot;Titel&quot; name=&quot;levels[][build_time]&quot;&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>The output I get now is:</p>
  <pre class="lang-none prettyprint-override"><code>[levels] =&gt; Array (
    [0] =&gt; Array ( [level] =&gt; 1 )
    [1] =&gt; Array ( [build_time] =&gt; 234 )
    [2] =&gt; Array ( [level] =&gt; 2 )
    [3] =&gt; Array ( [build_time] =&gt; 456 )
  )
  </code></pre>
  <p>As suggested in your edit, I edited my form and moved the square brackets to the end of the name. The output I get now is:</p>
  <pre class="lang-none prettyprint-override"><code>[levels] =&gt; Array (
    [level] =&gt; Array (
      [0] =&gt; 1
      [1] =&gt; 2
    )
    [build_time] =&gt; Array (
      [0] =&gt; 234
      [1] =&gt; 456
    )
  )
  </code></pre>
  <p>I guess that would kind of work, but it still looks complicated. Isn’t there a better way?</p>