我无法解释,但我目前正在尝试从保存在Cookie中的购物车中删除产品。
if(isset($_GET['remove'])) {
$remove = $_GET["remove"];
foreach($cart_saved as $q) {
if($q == $remove) {
unset($cart_saved[$q]);
setcookie("shop_items", json_encode($cart_saved), time() + 36000);
}
}
该值已从数组中删除,但我无法更新Cookie
答案 0 :(得分:0)
你每次都写下你的cookie是为什么有问题。所以:
if(isset($_GET['remove'])) {
$remove = $_GET["remove"];
foreach($cart_saved as $q) {
if($q == $remove) {
unset($cart_saved[$q]);
}
setcookie("shop_items", json_encode($cart_saved), time() + 36000);
}
答案 1 :(得分:0)
foreach($cart_saved as $key => $q) {
if($q == $remove) {
unset($cart_saved[$key]);
setcookie("shop_items", json_encode($cart_saved), time() + 36000);
break;
}
}