在 php 内从购物车中移除一件商品
Remove a single item from cart in php
我正在尝试从 cart.php 中删除单个项目,但它不起作用。我应该怎么办 ?这是我的代码:
<?php
error_reporting(0);
$item_id = $_GET["item_id"];
session_start();
if(!empty($_SESSION["incart"])) {
foreach($_SESSION["incart"] as $select => $val) {
unset($_SESSION["incart"]);
}
}
?>
print_r输出
Array (
[0] => Array (
[item_id] => 100002
[item_name] => Porsche
[item_price] => 200
[item_img] => porsche.jpg
[nowdate] => 40
[enddate] =>60
)
)
试试下面的代码:
<?php
error_reporting(0);
$item_id = $_GET["item_id"];
session_start();
if (!empty($_SESSION["incart"])) {
foreach ($_SESSION["incart"] as $select => $val) {
if($val["item_id"] == $item_id)
{
unset($_SESSION["incart"][$select]);
}
}
}
?>
我正在尝试从 cart.php 中删除单个项目,但它不起作用。我应该怎么办 ?这是我的代码:
<?php
error_reporting(0);
$item_id = $_GET["item_id"];
session_start();
if(!empty($_SESSION["incart"])) {
foreach($_SESSION["incart"] as $select => $val) {
unset($_SESSION["incart"]);
}
}
?>
print_r输出
Array (
[0] => Array (
[item_id] => 100002
[item_name] => Porsche
[item_price] => 200
[item_img] => porsche.jpg
[nowdate] => 40
[enddate] =>60
)
)
试试下面的代码:
<?php
error_reporting(0);
$item_id = $_GET["item_id"];
session_start();
if (!empty($_SESSION["incart"])) {
foreach ($_SESSION["incart"] as $select => $val) {
if($val["item_id"] == $item_id)
{
unset($_SESSION["incart"][$select]);
}
}
}
?>