I have a checkbox group in one form that I need to be posted.
<input type="checkbox" value="true" checked name="chk0[]">
<input type="checkbox" value="false" name="chk0[]">
<input type="checkbox" value="false" name="chk0[]">
<input type="checkbox" value="true" checked name="chk0[]">
<input type="checkbox" value="true" checked name="chk1[]">
<input type="checkbox" value="false" name="chk1[]">
<input type="checkbox" value="true" checked name="chk1[]">
<input type="checkbox" value="false" name="chk1[]">
Note that in the first group, 1 and 4 are checked. In the second group, 1 and 3 are checked.
When I post this, I get the posted values for the checked checkboxes sequentially as under:
[chk0] => Array (
[0] => true
[1] => true
)
[chk1] => Array (
[0] => true
[1] => true
)
How can I make sure I get the posted values like this:
[chk0] => Array (
[0] => true
[3] => true
)
[chk1] => Array (
[0] => true
[2] => true
)
I wanted to know the keys of the checked checkboxes instead of showing me sequentially.
Thanks
See what I mean?
The
<input name="chk0[1]" ...>boxes work just like array elements inside PHP. You can specify the indexes an they will be transfered as-is into PHP as$_POST['chk0'][1]elements.