我只是試圖寫一個函數在PHP中添加到折扣數組,但它似乎並沒有工作。
function addToDiscountArray($item){
// if we already have the discount array set up
if(isset($_SESSION["discountCalculator"])){
// check that this item is not already in the array
if(!(in_array($item,$_SESSION["discountCalculator"]))){
// add it to the array if it isn't already present
array_push($_SESSION["discountCalculator"], $item);
}
}
else{
$array = array($item);
// if the array hasn't been set up, initialise it and add $item
$_SESSION["discountCalculator"] = $array;
}
}
我每次刷新它就像$ _SESSION [「discountCalculator」]尚未建立的頁面,但我不明白爲什麼。寫作時,我可以以正常的方式在foreach php循環中使用$ _SESSION [「discountCalculator」]?
非常感謝
在做任何事情之前你做過'session_start()'嗎? ''_SESSION'總是存在,但是在執行'session_start()'後會只填充存儲的值' – 2011-04-06 16:30:49
非常感謝,我最初編寫了頭文件,並且在那裏有session_start(),所以假設它仍然會是的,但現在自從你提到它以來我就去檢查它了,看起來我正在構建該網站的人之一在他調整模板時已將其取出。謝謝 – ComethTheNerd 2011-04-06 16:35:00