0

我正在创建一个$item我想推送到的数组$_SESSION['cart']。构建我的item数组后,我正在尝试:

$_SESSION['cart'][] = $item[$item_id];

参考: 我可以在 php 中的 SESSION 数组上使用 array_push 吗?

但是,我的购物车会话变量不断被覆盖,而不是被添加到。还有其他建议吗?

根据马克的要求:

第一次运行:

Notice: Undefined variable: _SESSION in C:\inetpub\wwwroot\domain\store\cart.php on line 5
NULL array(3) { ["title"]=> string(37) "PA State and Federal Laminated Poster" ["price"]=> string(5) "55.95" ["qty"]=> string(1) "3" }

第二次:

Notice: Undefined variable: _SESSION in C:\inetpub\wwwroot\domain\store\cart.php on line 5
NULL array(3) { ["title"]=> string(53) "PA State and Federal Laminated Poster SPANISH Edition" ["price"]=> string(5) "55.95" ["qty"]=> string(1) "1" }
4

1 回答 1

1

session_start()您必须在参考之前致电$_SESSION。您发布的输出表明您不这样做。

注意:未定义变量:第 5 行 C:\inetpub\wwwroot\domain\store\cart.php 中的 _SESSION

于 2012-08-22T17:33:45.943 回答