This is the array result that I get from a function. I want to get the category_id from the array and only echo it.
{"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"}
after I json_decode my result, it shows like this.
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 )
How to access the category_id when there is 2 stdclass object
//solved it
foreach ($arr as $obj => $arr) {
foreach ($arr as $obj => $arr) {
print_r($arr->category_id);
}
}