I'm trying to loop through JSON data in php.
array:2 [
"cart" => array:3 [
0 => array:4 [
"id" => 3
"name" => "ying"
"price" => "4000"
]
1 => array:4 [
"id" => 2
"name" => "yang"
"price" => "4000"
]
2 => array:4 [
"id" => 4
"name" => "foo"
"price" => "5000"
]
]
"total" => 13000
]
I've used the json_decode function and a foreach over the data.
foreach (json_decode($arr) as $item) {
$item['name'];
}
I want to be able to get each "cart" item and the single "total" data but I keep getting an illegal offset error when i try to call things like $item['name']