开发者

Get values from select items with same name

开发者 https://www.devze.com 2022-12-30 08:54 出处:网络
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 bello

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消