Hi all

This is probably the easiest question ever, but I am not familiar with arrays , so hope somebody can help me

User post this checkbox form:

<input type="checkbox" name="type[0][]" value="1" >
<input type="checkbox" name="type[0][]" value="2" >
<input type="checkbox" name="type[0][]" value="3" >

I need to get all checked values and print them ...
How can I do this?

I tried the code below, but it only returns me one value


$values = array($_POST["type"]);

foreach ($values as $item){

 echo $item;

}

Any help???

Thanks!!

    Do a [man]print_r/man on the $_POST array to better understand how the array ends up being created.

      bradgrafelman;10964961 wrote:

      Do a [man]print_r/man on the $_POST array to better understand how the array ends up being created.

      thanks for the tip
      i am getting the post correctly

      Array ( [0] => Array ( [0] => 3 [1] => 1 [2] => 2 ) )

      Any other idea?

      Thanks

        Other ideas for what? Did you have an other question, or is there something you don't understand?

          kelsjc;10964967 wrote:

          Array ( [0] => Array ( [0] => 3 [1] => 1 [2] => 2 ) )

          This tells you that the variable $_POST['type'] is an array with one item - located in index 0. That item is another array - one with three numerically-indexed values (3, 1, and 2).

          Also, this:

          $values = array($_POST["type"]);

          is redundant. You're taking the multidimensional array above and placing it as the sole value in yet another encompassing array.

            bradgrafelman;10964981 wrote:

            This tells you that the variable $_POST['type'] is an array with one item - located in index 0. That item is another array - one with three numerically-indexed values (3, 1, and 2).

            Also, this:

            $values = array($_POST["type"]);

            is redundant. You're taking the multidimensional array above and placing it as the sole value in yet another encompassing array.

            Hi, thanks for your answer.
            Because its multidimensional array, i had to put [0] after it.
            I got it solved now :

            foreach ($_POST["type"][0] as $item){
            
             echo $item;
            
            }
            

            Thanks again!

              Don't forget to mark this thread resolved (if it is) using the link on the Thread Tools menu above.

                Write a Reply...