我在更新PHP的$_SESSION
变量的数组元素时遇到问题。这是基本结构:php中的多维数组SESSION
$product = array();
$product['id'] = $id;
$product['type'] = $type;
$product['quantity'] = $quantity;
,然后使用array_push()
功能我插入SESSION变量产品。
array_push($_SESSION['cart'], $product);
现在,这是I M面临的问题主要部分:
foreach($_SESSION['cart'] as $product){
if($id == $product['id']){
$quantity = $product['quantity'];
$quantity += 1;
$product['quantity'] = $quantity;
}
}
欲$_SESSION['cart']
可变内递增的产品数量。我怎样才能做到这一点?