Reputation: 35
I have 1000 checkboxes of object fields and I want to create an Array from all the fields that I check after submitting using PHP can you tell me how to do it?
Upvotes: 0
Views: 28
Reputation: 411
<input type="checkbox" name="somename[]" value="somevalue">
if you need an array with numerical indices
or
<input type="checkbox" name="someobject[property]" value="somevalue">
if you are looking for an associative array
Upvotes: 0
Reputation: 12939
well if you name your checkbox like this, you already have an array:
<input name="mycheckbox[]" value="1"> hello1
<input name="mycheckbox[]" value="2"> hello2
<input name="mycheckbox[]" value="3"> hello3
in PHP you will get:
print_t($_REQUEST['mycheckbox']);
/*
[
0 => '1',
0 => '2',
0 => '3'
]
*/
Upvotes: 1