I have 10 checkboxes, like so
<input type="hidden" name="box1" value="0"><input type="checkbox" id="box1" name="box1" value="1">
<input type="hidden" name="box2" value="0"><input type="checkbox" id="box2" name="box2" value="1">
<input type="hidden" name="box3" value="0"><input type="checkbox" id="box3" name="box3" value="1">
and so forth. These checkboxes are all inside a form, and when submitted will go to a PHP script. How am I able to access the values (on or off) for each one. So far I have tried using this:
<input type="hidden" name="box[]" value="0"><input type="checkbox" id="box1" name="box[]" value="1">
<input type="hidden" name="box[]" value="0"><input type="checkbox" id="box2" name="box[]" value="1">
<input type="hidden" name="box[]" value="0"><input type="checkbox" id="box3" name="box[]" value="1">
with
$x = $_POST["box"];
foreach ($x as $y){
echo $y . "</br>";
}
But this gives random, inaccurate results (say for example box 1, 3 and 4 are clicked, it may give something like this: [0, 0, 0, 1, 1, 0, 0, 1], with 1 being on and 0 off). Can anyone give me a hint in the right direction? Thank you in advance