將購物車與「添加到購物車」功能組合在一起。除了從購物車中移除物品之外,一切都可以使用。這裏是什麼,我有簡化的版本,使其更容易看到問題的所在:如何刪除一個PHP SESSION數組中的行?
$action = $_GET['action'];
$id = $_GET['id'];
if ($action == "remove"){
unset($_SESSION['cart'][$product_id][$id]);
//Also tried this without sucess: $_SESSION['cart'][$product_id]--;
}
foreach($_SESSION['cart'] as $product_id) {
echo 'Details'.$product_id['title'].' - '.$product_id['price'];
echo '<a href="Cart.php?action=remove&id='.$product_id['product_id'].'">Remove</a>';
}
得到你的答案! :)讓我知道它是否有效 – KyleK