【发布时间】:2012-02-08 16:07:32
【问题描述】:
假设我有 $_SESSION['cart'];当我打印这个
echo "<pre>",print_r($_SESSION['cart']),"</pre>";
它会显示类似的东西
Array
(
[1] => 2
[2] => 2
)
其中键是产品 ID,值是每个产品的数量。 所以,如果我想删除产品编号。来自该会话数组的 2 个, 我该怎么做?
我尝试了我想到的最快的功能
public function removeItem($id2){
foreach($_SESSION['cart'] as $id => $qty) {
if ($id == $id2){
unset($_SESSION['cart'][$id]);
}
}
}
它删除了整个 $_SESSION['cart'] 数据:(
【问题讨论】:
标签: php