This is a nice easy one :)

It couldn't be simpler.

Just put empty square brackets (as used in arrays) in front of your
checkbox name.
The example below assumes you have PHP 4.1 or greater (which uses
$_POST to contain form posted data)
notice how name="ck[]"


    if(count($_POST)) {
        foreach ($_POST["ck"] as $varval) {

<form action="test.php" method="post">

<input type="checkbox" name="ck[]" value="val1"><br>
<input type="checkbox" name="ck[]" value="val2"><br>
<input type="checkbox" name="ck[]" value="val3"><br>
<input type="checkbox" name="ck[]" value="val4"><br>
<input type="checkbox" name="ck[]" value="val5"><br>
<input type="submit">


in earlier versions of PHP, $_POST["ck"] would be equal to $ck
(although, the former is safer)

On Thu, 4 Jul 2002 10:52:37 +0200, "Uwe Birkenhain"
> Hi everybody on this rainy morning!
> My problem:
> I give the user a form with a list of options with checkboxes.
> The list is long and not predictable - the values change always.
> I want to put the checked values (or all, that doesn't matter) in an
> array,
> to pass it to my function.
> How can I write those keys and values in an array?
> I suppose it will be best done with JS - but since I don't know JS ...
> Has anybody a ready solution?
> Thank's a lot!
> Uwe
> -- 
> PHP General Mailing List (
> To unsubscribe, visit:


PHP General Mailing List (
To unsubscribe, visit:

Reply via email to