这是我从函数中得到的数组结果。我想从数组中获取 category_id 并且只回显它。
{"categories": [{"parent_id": 15397, "has_children": true, "category_id": 15402, "category_name": "AC"}, {"parent_id": 0, "has_children": true, "category_id": 15397, "category_name": "A"}], "request_id": "3beac0674e937d2471e4b66b5f998976"}
在我 json_decode 我的结果之后,它显示如下。
stdClass Object ( [categories] => Array ( [0] => stdClass Object ( [parent_id] => 0 [has_children] => 1 [category_id] => 16 [category_name] => Women's Clothing ) [1] => stdClass Object ( [parent_id] => 16 [has_children] => 1 [category_id] => 1585 [category_name] => Dresses )
有2个stdclass对象时如何访问category_id
//solved it
foreach ($arr as $obj => $arr) {
foreach ($arr as $obj => $arr) {
print_r($arr->category_id);
}
}
慕姐4208626
jeck猫