tags:

views:

35

answers:

2

Hello,

I have a HTML form with a variable number of select fields. Each select field represents the same category, so I named all the selects like mySelect[]. The code I wrote for getting the values is bellow:

for ($i = 0; $i < count($_POST['mySelect']); $i++) {
    echo $_POST['mySelect'][$i];
}

But I don't get any results. What is wrong?

Thanks.

A: 

What happens if you do:

var_dump($_POST['mySelect']);

Also, what about using foreach instead of for:

foreach ($_POST['mySelect'] as $key => $value) {
    echo $value;
}
ircmaxell
var_dump returns `string(5) "Array"`
Psyche
@Psyche: So `$_POST['mySelect']` contains a string `"Array"` and not an array ;)
Felix Kling
is there any processing of $_POST before this (perhaps in a framework, or perhaps a stripslashes)? Something's doing $_POST['mySelect'] = (string) $_POST['mySelect'];
ircmaxell
@ircmaxell: no, there isn't such processing.
Psyche
A: 
<input type="text name="item[]" value="item1" />
<input type="text name="item[]" value="item2" />
<input type="text name="item[]" value="item3" />

<pre>
<?php print_r( $_POST[ 'item' ] ); ?>
</pre>
David Morrow