我只是试图写一个函数在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