我在使用$_SESSIONPHP变量更新数组元素时遇到问题.这是基本结构:
$product = array();
$product['id'] = $id;
$product['type'] = $type;
$product['quantity'] = $quantity;
Run Code Online (Sandbox Code Playgroud)
然后通过使用array_push()函数我在SESSION变量中插入该产品.
array_push($_SESSION['cart'], $product);
Run Code Online (Sandbox Code Playgroud)
现在这是我面临问题的主要部分:
foreach($_SESSION['cart'] as $product){
if($id == $product['id']){
$quantity = $product['quantity'];
$quantity += 1;
$product['quantity'] = $quantity;
}
}
Run Code Online (Sandbox Code Playgroud)
我想在$_SESSION['cart']变量中增加产品数量.我怎样才能做到这一点?