我在删除购物车项目的会话数组中的项目时遇到问题。以下代码应获取所选项目并将其从会话中删除。然而,最终结果与之前的会话相同,没有任何内容被删除。我通过谷歌搜索看到了类似的问题,但还没有找到可行的解决方案。这是精简的代码:
<?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
)
我错过了一些明显的东西吗?