나는 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
이 (NULL
) 설정되어 있기 때문에
많은 감사
무엇을하기 전에'session_start()'를 했습니까? '$ _SESSION'은 항상 존재하지만,'session_start()'를 수행 한 후에 만 저장된 값으로 채워질 것입니다. –
고맙습니다. 처음에는 헤더 스크립트를 썼고 거기에 session_start()를 넣어 두었습니다. 하지만, 지금은 당신이 그것을 언급 한 이래로 나는 그것을 확인하기 위해 갔다. 그리고 그가 웹 사이트를 만들고있는 사람들 중 하나가 그가 템플릿을 조정할 때 그것을 꺼냈다 고 보인다. 감사합니다 – ComethTheNerd