[thelist] PHP - multiple checkboxes

Carl-Johan Kihlbom div at newcode.se
Fri Sep 21 11:32:39 CDT 2001


On fredag, september 21, 2001, at 05:20 , Bruce Heerssen wrote:

> I have a form with multiple checkboxes that all have the same name, and 
> I need to get the value for each one, but when I test for it, it 
> returns the last value followed by a series of commas.
>
> Can someone tell me how to access them correctly in PHP?
>
> Thanks,
>
> Bruce

Same way as in the thread "Multiple Select".

Add [] after the name, to indicate to the receiving PHP script that it 
should treat it as an array. Like this:

<input type="checkbox" name="foo[]" value="bar 1">
<input type="checkbox" name="foo[]" value="bar 2">
and so on...

Then you will receive the values in an array called $foo.

$foo[0] == "bar 1";
$foo[1] == "bar 2";

/ Carl-Johan




More information about the thelist mailing list