<?php
session_start();
if(!empty($_SESSION["cart_item"])) {
if(in_array($_GET['code'],$_SESSION["cart_item"])){
echo "hiiii";
}else{
echo "byeee";}
}else {
$itemArray = array($_GET['code']=>array('pcode'=>$_GET['code']));
$_SESSION["cart_item"] = $itemArray;
}
?>
I'm trying to check if there is a similar item store in the $_SESSION[cart_item] using in_array but it only return me false although i make sure that the value is indeed store in $_SESSION.
As i go through some checking, since my $_SESSION has a multidimensional array, i should use array_key_exists and here is my code for this
if(array_key_exists($_GET['code'],$_SESSION["cart_item"])){
echo "hiiii";
}else{
echo "byeee";}
But still it returns false. Can anyone point out my error?
btw I'm new to this and thanks in advance.
$_SESSION["cart_item"]array.if(!empty($_SESSION["cart_item"]))toif(isset($_SESSION["cart_item"]))