如何循环遍历JSON数据php [英] How to loop through json data php
本文介绍了如何循环遍历JSON数据php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试遍历php中的JSON数据.
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
]
我使用了json_decode函数和对数据的foreach.
I've used the json_decode function and a foreach over the data.
foreach (json_decode($arr) as $item) {
$item['name'];
}
我希望能够获取每个购物车"商品和单个总计"数据,但是当我尝试调用$ 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']
推荐答案
查看全文