我在购物车项目中删除会话数组中的项目时遇到问题。以下代码应该将所选项目从会话中删除。然而,最终结果与之前的会话没有任何关系。我看到类似的问题,谷歌搜索,但还没有找到一个工作解决方案。这里是精简代码:删除会话中的项目
<?php
session_start();
$removeditem = $_GET['item']; // this identifies the item to be removed
unset($_SESSION['stuff'][$removeditem]); // "stuff" is the existing array in the session
?>
这里是什么的print_r给出了以下(使用“7”为已删除的项目为例):
$removeditem:
7
$_SESSION['stuff'] (before and after removal)
Array
(
[0] => 7
[1] => 24
[2] => 36
)
我失去了一些东西明显?
啊是的,关键与价值是问题。奇迹般有效。谢谢您的帮助! – funfetti 2010-08-23 16:17:01
这对我来说非常合适。谢谢。 – 2016-10-13 14:26:49