After dumping session, I get below result. Can anybody please tell me how I can get the value "product_id" and "info" that are in array(2);
array(3) {
["DYN_outskin"]=> string(3) "ten"
["DYN_inskin"]=> string(3) "one"
["cart"]=> array(1) {
["2000_facebook"]=> array(2) {
["product_id"]=> string(13) "2000_facebook"
["info"]=> string(7) "nur1952"
}
}
}
Try like this:
$array['cart']['2000_facebook']['product_id'];
$array['cart']['2000_facebook']['info'];
$_SESSION["cart"]["2000_facebook"]["product_id"] ;
$_SESSION["cart"]["2000_facebook"]["info"] ;
iterate over cart:
foreach ($_SESSION["cart"] as $product){
echo "Product info : {$product['info']} | Product ID : {$product['product_id']} <br/>" ;
}
It is always a good practice to display the array in a way that clearly displays the array structure, like so:
array(3) {
["DYN_outskin"]=> string(3) "ten"
["DYN_inskin"]=> string(3) "one"
["cart"]=> array(1) {
["2000_facebook"]=> array(2) {
["product_id"]=> string(13) "2000_facebook"
["info"]=> string(7) "nur1952"
}
}
}
Now, its clear how you can access the needed elements:
$array["cart"]["2000_facebook"]["product_id"]
$array["cart"]["2000_facebook"]["info"]