include('session.php');
$productname = $_GET['productname'];
$productcode = $_GET['productcode'];
$wishlist = array("$productname" => $productcode);
$_SESSION["wishlist"] = $wishlist;
print_r($_SESSION["wishlist"]);
이 코드는 "wishlist"라는 세션에 대한 배열로 설정됩니다.
문제는 세션이 대체되고 있다는 것입니다. 이미 존재하는 경우 배열에 추가하고 싶습니다.세션에 저장하는 연관 배열에 값을 추가하는 방법은 무엇입니까?
그래서 배열을 새 데이터로 업데이트 할 수 있습니까? 나는 다음을 시도했다.
$productname = $_GET['productname'];
$productcode = $_GET['productcode'];
$lastsession = $_SESSION["wishlist"];
// CHECK IF SESSION IS EMPTY OR NOT
if(empty($lastsession)) {
$wishlist = array("$productname" => $productcode);
} else {
/*
How Can I Update array ???
*/
}
배열 출력은 이와 유사합니다. 숫자와 연관된 인덱스가 아니기 때문에 연관됩니다. 그리고 하나의 배열에 결과를 원한다. 배열로 배열되지 않습니다.
[mobile] => iphone_2
감사합니다.
은 내가 세션에서 많은 값을 어떻게 저장하는 경우? upto 10+ mb – TarangP
[이 링크] (https://stackoverflow.com/a/4649934/3578036)가 질문에 대한 답변을 제공합니까? 세션의 기본 최대 크기는 128MB – JustCarty
array_push ($ wishlist, array ("$ productname"=> $ productcode))입니다. 이 배열에 새 배열을 만듭니다. 난 단지 배열이 아니라 값을 추가하고 싶어 그래서 어떤 솔루션을 가지고 있습니까? – TarangP