title: Loop through DIV elements and get dynamically added text inputs - PHP
body: <p>I have a form on a web page that allows for dynamically added divs with text inputs inside them (via JavaScript) into a div called "actorsDivHTML". So the structure is as follows:</p>
  
  <pre><code>&lt;div name="actorsDivHTML"&gt;
  
      &lt;div name="actor[]"&gt;
          &lt;input type="text" name="actorName[]"&gt;
          &lt;div name="actorInfoDiv[]"&gt;
              &lt;input type="text" name="actorInfo[]"&gt;
              &lt;input type="text" name="actorInfo[]"&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div name="actor[]"&gt;
          &lt;input type="text" name="actorName[]"&gt;
          &lt;div name="actorInfoDiv[]"&gt;
              &lt;input type="text" name="actorInfo[]"&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;/div&gt; 
  </code></pre>
  
  <p>Note: I am unsure if a div is allowed to be used the same way an input is -> ie. "div[]"</p>
  
  <p>My aim is to allow the user to dynamically add as many "actors" as possible with as many "actorInfo" inputs for each "actor" as they require. When the user submits the form, I have a PHP file that will need to get each "actor" and each "actorInfo" from the "actorsDivHTML" div.</p>
  
  <p>My questions are; 
  what is the best way to name each div so the info can be easily extracted by the PHP script? What is the best way to iterate through the div and extract the information that I need (ie. each actor and the info about them), and place them into an array of the following structure:</p>
  
  <pre><code>Array(
      [actor] =&gt; Array([0] =&gt; "name", [1] =&gt; Array([0] =&gt; "info1", [1] =&gt; "info2", etc.))
      [actor] =&gt; Array([0] =&gt; "second name", [1] =&gt; Array([0] =&gt; "actor 2 info1", etc.))
  )
  </code></pre>
  
  <p>Happy to clarify and share more code!</p>
  
  <p>Cheers!</p>
  
  <p>[EDIT: 1]</p>
  
  <p>In response to Pupil:</p>
  
  <p>I have updated my Div's to look like this:</p>
  
  <pre><code>&lt;div class="actorTest"&gt;
  
     &lt;div name="actorDivPlace"&gt;
         &lt;input type="text" name="actorNameTest[name]"&gt;
         &lt;div name="actorInfoDiv"&gt;
             &lt;input type="text" name="actorNameTest[name][]"&gt;
             &lt;input type="text" name="actorNameTest[name][]"&gt;
          &lt;/div&gt;
     &lt;/div&gt;
  
      &lt;div name="actorDivPlace"&gt;
          &lt;input type="text" name="actorNameTest[name]"&gt;
          &lt;div name="actorInfoDiv"&gt;
              &lt;input type="text" name="actorNameTest[name][]"&gt;
              &lt;input type="text" name="actorNameTest[name][]"&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>and when I run <code>print_r($_POST["actorNameTest"])</code> I only get the last actor:</p>
  
  <pre><code>Array ( [name] =&gt; Array ( [0] =&gt; second info [1] =&gt; second second info) ) 
  </code></pre>