I've been trying to parse this JSON code (It's $customer_cart['products']
output):
{
"Bag0145cm":{
"name":"Pizza",
"code":"Bag0145cm",
"price":"9.50",
"size":"45cm",
"short_desc":"Shortdesc",
"quantity":"1",
"image":"IMG"
},
"Laptop0135cm":{
"name":"Pizza2",
"code":"Laptop0135cm",
"price":"8.00",
"size":"35cm",
"short_desc":"Shortdesc",
"quantity":"1",
"image":"IMG"
}
}
I'd like to get output all listed product names like this:
Pizza
Pizza2
I've tried this kind of code but getting foreach error
$array = json_decode($customer_cart['products'], true);
foreach($array as $product) {
echo $product->name;
}