2012-08-22 21 views
0

我正在創建一個$item數組,我想推到$_SESSION['cart']。構建我item陣列後,我想:將數組推送到會話變量而不重新實例化變量

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

引用: Can I use array_push on a SESSION array in php?

然而,我的購物車會話變量不斷得到覆蓋,而不是加入。還有其他建議嗎?

正如馬克要求:

第一次正在運行:

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" } 
+1

你能提供一個'的var_dump('? – Matt

+3

你在'$ _SESSION ['cart'] [] = $ item [$ item_id];''之前調用'session_start() 'notice'表示你沒有。 – Matt

+0

就是這樣。你可以添加這個答案,以便我可以分配點嗎?謝謝! – etm124

回答

1

你得叫你session_start()引用$_SESSION之前。你發佈的輸出表明你不這樣做。

注意:未定義的變量:_SESSION在C:\的Inetpub \ wwwroot的\域\店\上線)之前和之後cart.php 5