我在html中有代码:
<input type="text" name="product[0][name]" value="name of product 1"/>
<input type="text" name="product[1][name]" value="name of product 2"/>
<input type="text" name="product[2][name]" value="name of product 3"/>
<input type="text" name="product[3][name]" value="name of product 4"/>
我尝试通过 $_POST 发送这个。当我使用
print_r($_POST['product']);
我得到了我的产品清单:
Array
(
[product] => Array
(
['201'] => Array
(
['name'] => J5313 BEŻOWE
['price'] => 14.99
['quantity'] => 1
['size'] => 36
['product_subtotal'] => 14.99
)
['200'] => Array
(
['name'] => J5313 SZARE
['price'] => 14.99
['quantity'] => 1
['size'] => 37
['product_subtotal'] => 14.99
)
)
)
一切都很好,但是如果我想回显我的数组变量,我有空变量!它是我的代码:
foreach($_POST['product'] as $key => $value){
echo "product key: $key, product name: ".$value['name']."";
}
php 在文档中写的内容:
product key: 0, product name:
product key: 1, product name:
product key: 2, product name:
product key: 3, product name:
$key 变量不为空,但 $value 为空!我尝试更改 $value var 的名称,但它不能解决我的问题。任何人都知道我必须做什么?