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开发者_如何学Go any results. What is wrong?
Thanks.
<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>
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;
}
精彩评论