I would like to make multidimensional array but after looking on it for hours I am quite lost. I am sending ID and quantity from modal via AJAX, and I want to store it like this $_SESSION['cart'] =>array(here should be IDs => and each ID is pointing to its quantity)
if(!isset($_SESSION['cart'])){
$_SESSION['cart'] = array(array());
}
if(isset($_REQUEST['id'])){
$_SESSION['cart'][] = $_REQUEST['id'];
$_SESSION['cart'][][] = $_REQUEST['quantity'];
}
I am trying to access it like that:
foreach($_SESSION['cart'] as $value){
//var_dump($value);
//echo "<br>";
foreach($value as $item){
var_dump($item);
echo "<br>";
}
}
But for second foreach I get warning that its argument is invalid, which I can bypass with converting the $value to array. Is this the right way to do it ? or is there any better ? Thanks