来自$ _get的一个参数中的多个值

时间:2017-06-24 11:01:18

标签: php html forms input

我有一个html表单,其中一个参数提交了多个值。 我怎么能在php中处理它

整件事看起来像这样:

单个参数:
shoppingcart =第1项 shoppingcart =第2项 shoppingcart =第3项 shoppingcart =第3项 名称=最大
姓氏=布朗
地址=纽约

5 个答案:

答案 0 :(得分:1)

如果您提交数组,则应将其用作数组,例如:

$my_item_array  = $_GET['shoppingcart '];


foreach($my_item_array as $key => $value){

 echo $value . <br />;
}

答案 1 :(得分:1)

在html格式shoppingcart[]中使用参数作为数组类型,你可以将它放在php循环中。

foreach($_GET['shoppingcart'] as $item){
        echo $item;
}

答案 2 :(得分:1)

您可以像这样使用它,

形式,

&#13;
&#13;
item1: <input type="text" name="shoppingcart[]"/>
item2: <input type="text" name="shoppingcart[]"/>
&#13;
&#13;
&#13;

然后在你的PHP代码中,

$items = $_GET["shoppingcart"];

答案 3 :(得分:1)

您必须为名称分配类似

的数组
<input type="text" name="shoppingcart[]"/>

答案 4 :(得分:0)

$ _ GET是PHP中的全球变体。它是数组,您可以按以下形式使用它:

想象一下有以下html表单:

<form action="welcome_get.php" method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

和welcome_get.php看起来像这样:

Welcome <?php echo $_GET["name"]; ?><br>
Your email address is: <?php echo $_GET["email"]; ?>