Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As a perhaps more flexible alternative to array_chunk (since you may have more "incorrect answers" in the future and that would require to keep updating the array_chunk size param), you can go with the following:</p> <p>In your javascript snippet, where you are populating the DOM elements, you can populate your name attribute as a multidimensional array (I renamed from items to questions for conceptual purposes):</p> <pre><code>$('&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;p&gt;&lt;span class="left"&gt;&lt;input type="text" class="dynamic-input" name="questions[' +i +'][]" id="' + i + '" placeholder="Question" /&gt;&lt;/span&gt;' + '&lt;span class="right"&gt;&lt;input type="text" class="dynamic-input" name="questions[' +i +'][]" id="' + i + '" placeholder="Distraction 1" /&gt;&lt;br /&gt;&lt;input type="text" class="dynamic-input" name="questions[' +i +'][]" id="' + i + '" placeholder="Distraction 2" /&gt;&lt;br /&gt;&lt;input type="text" class="dynamic-input" name="questions[' +i +'][]" id="' + i + '" placeholder="Distraction 3" /&gt;&lt;br /&gt;&lt;input type="text" class="dynamic-input" name="questions[' +i +'][]" id="' + i + '" placeholder="Correct Answer" /&gt;&lt;br /&gt;&lt;a href="#"&gt;Remove&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;').fadeIn("slow").appendTo('#extender'); </code></pre> <p>So this would be an array of question arrays.</p> <p>In the PHP side (similar to the array_chunk post), you can use implode as such:</p> <pre><code>if(!empty($_POST['questions'])) { foreach($_POST['questions'] as $question) { echo implode(',',$question) ."\n"; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload