switch($action)
{
case "add":
if (isset($_SESSION['cart'][$id]))
$_SESSION['cart'][$id]++;
else
$_SESSION['cart'][$id]=1;
break;
case "remove":
if (isset($_SESSION['cart'][$id]))
(
$_SESSION['cart'][$id]--; (ERROR HERE)
if ($_SESSION['cart'][$id]==0)
unset($_SESSION['cart'][$id]);
)
break;
case "empty":
unset($_SESSION['cart']);
break;
}
您在 IF 语句中使用括号而不是方括号:
if (isset($_SESSION['cart'][$id]))
( <-- HERE
$_SESSION['cart'][$id]--; (ERROR HERE)
if ($_SESSION['cart'][$id]==0)
unset($_SESSION['cart'][$id]);
) <-- HERE