在此代码删除案例中,执行比会话获取负值更多的时间。会话代码中发生的更改类型仅获取正值。
<?php
session_start();
$d1=$_POST['d1'];
$action=$_POST['str1'];
$product_id = $_POST['productid'];
switch($action)
{
case "Add":
$_SESSION['cart'][$product_id] = $d1 + (isset($_SESSION['cart'][$product_id]) ?$_SESSION['cart'][$product_id] : 0);
break;
case "Remove":
$_SESSION['cart'][$product_id]=(isset($_SESSION['cart'][$product_id]) ? $_SESSION['cart'][$product_id] : 0)- $d1;
if($_SESSION['cart'][$product_id] == 0)
unset($_SESSION['cart'][$product_id]);
break;
}
?>