Note that there are some explanatory texts on larger screens.

plurals
  1. POUnchecked checkboxes in an array
    text
    copied!<p>I'm building a form with the possibility to add more group of fields, to process them i read out the array in a for loop</p> <p>the script:</p> <pre><code>&lt;?php foreach ($_POST as $key =&gt; $value) { $$key = $value; } $count = count($name); for ($i=0; $i&lt;$count; $i++){ ?&gt; &lt;strong&gt;&lt;?php echo $name[$i]; ?&gt;&lt;/strong&gt; (&lt;?php echo $check[$i]; ?&gt;)&lt;br /&gt;&lt;?php echo $select[$i]; ?&gt;&lt;br /&gt;&lt;br /&gt; &lt;?php } ?&gt; &lt;form method="post"&gt; &lt;div class="group"&gt; &lt;input type="text" name="name[]" /&gt;&lt;br /&gt; &lt;input type="checkbox" name="check[]" value="true" /&gt;&lt;br /&gt; &lt;select name="select[]"&gt;&lt;option&gt;1&lt;/option&gt;&lt;option&gt;2&lt;/option&gt;&lt;option&gt;3&lt;/option&gt;&lt;/select&gt; &lt;/div&gt; &lt;div class="group"&gt; &lt;input type="text" name="name[]" /&gt;&lt;br /&gt; &lt;input type="checkbox" name="check[]" value="true" /&gt;&lt;br /&gt; &lt;select name="select[]"&gt;&lt;option&gt;1&lt;/option&gt;&lt;option&gt;2&lt;/option&gt;&lt;option&gt;3&lt;/option&gt;&lt;/select&gt; &lt;/div&gt; &lt;div class="group"&gt; &lt;input type="text" name="name[]" /&gt;&lt;br /&gt; &lt;input type="checkbox" name="check[]" value="true" /&gt;&lt;br /&gt; &lt;select name="select[]"&gt;&lt;option&gt;1&lt;/option&gt;&lt;option&gt;2&lt;/option&gt;&lt;option&gt;3&lt;/option&gt;&lt;/select&gt; &lt;/div&gt; &lt;button&gt;Add another group&lt;/button&gt; &lt;input type="submit" /&gt; &lt;/form&gt; </code></pre> <p>If all checkboxes are checked there is no problem but if only the last one is checked it counts only one checkbox in the array, name[0] is then combined with check[0] but check[0] is really check[2]. English is not my native language so i don't know the right words.</p>
 

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