Souradip Mandal
Souradip Mandal

Reputation: 35

How to create an Array from the checked boxes

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

Answers (2)

Hisham
Hisham

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

Alberto
Alberto

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

Related Questions