【发布时间】:2023-03-08 22:43:01
【问题描述】:
我正在用 PHP 编写一个自定义购物车,我将产品信息添加到购物车会话中,如下所示:
$product_array=array($title,$price,$qty);
if(!isset($_SESSION['cart']))
$_SESSION['cart']=array();
if(!in_array($product_array,$_SESSION['cart']))
$_SESSION['cart'][]=$product_array;
else
{
// update price and quantity here
}
我的挑战:如果产品已存在于 $_SESSION['cart'] 数组而不是添加它。像这样的
price = price + $price,
qty = qty + $qty
【问题讨论】:
标签: php arrays multidimensional-array session-variables cart