2017-06-24 31 views
1

我有一個html表單,其中一個參數提交了多個值。 我該如何處理它在PHP

整個事情是這樣的:

單參數:
購物車=項目1個
購物車=第2項
購物車=項目3
購物車=項目3
名稱=最大
姓=布朗
ADRESS =紐約

+1

一個陣列請張貼HTML形式.. –

+1

你可以用'購物車[ ]'領域,你會得到數組值。 –

回答

1

你必須指定名稱,如

<input type="text" name="shoppingcart[]"/> 
1

如果你提交一個數組,你應該把它作爲一個數組例如:

$my_item_array = $_GET['shoppingcart ']; 


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

echo $value . <br />; 
} 
1

使用參數作爲數組類型的HTML表單shoppingcart[],您可以漢勒它的PHP循環。

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

$ _GET是超級全球varieble在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"]; ?> 
1

您可以使用它像這樣,

形式,

item1: <input type="text" name="shoppingcart[]"/> 
 
item2: <input type="text" name="shoppingcart[]"/>

在PHP代碼

然後,

$items = $_GET["shoppingcart"]; 
相關問題