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 (array): <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; } Code (markup): Any help??? Thanks!!
try what axelay posted but for an explanation of why its not working. Your only getting 1 value because it is a multidimensional array. So when you say foreach it is looking at the [0] you have, it looks for type[0], type[1], type[2].....and so on. You only have type[0] so it returns that first 1 and stops.
I believe that this is what you are looking for: <?php function print_array($array) { print_r($array); } Code (markup): Then all you need to do is pass $_POST to that function like this: print_array($_POST);
That would print everything in $_POST though, if all he has is the check box array then that would work but if there is more form fields its going to print it all, not just the check box array.
One last thing: I need to use this is a sql query. When I place this information into my WHERE condition, I get the last value How to get them as differents variables? should I use "for" instruction?! $values = array($_POST["type"][0]); foreach ($values as $item){ echo $item; $where_str = " AND gu.id_item='".$item."' "; } Code (markup):