facebook Batch request api gives me the response.and as according to my logic this is the best response i get i want to access the root element “source_id” and “copied_id” inside the [BODY].
i just want to access them in minimum loops.
i am currently using nested loops.
Array(
[0] => Array
(
[0] => stdClass Object
(
[code] => 200
[body] => {"copied_adset_id":"15454","ad_object_ids":[{"ad_object_type":"ad_set","source_id":"545454","copied_id":"15454"}]}
)
[1] => stdClass Object
(
[code] => 200
[body] => {"copied_adset_id":"1547754","ad_object_ids":[{"ad_object_type":"ad_set","source_id":"566454","copied_id":"1547754"}]}
)
)
[1] => Array
(
[0] => stdClass Object
(
[code] => 200
[body] => {"copied_adset_id":"1500454","ad_object_ids":[{"ad_object_type":"ad_set","source_id":"598754","copied_id":"1500454"}]}
)
[1] => stdClass Object
(
[code] => 200
[body] => {"copied_adset_id":"78448","ad_object_ids":[{"ad_object_type":"ad_set","source_id":"541230","copied_id":"78448"}]}
)
))
The body contain the JSON response below is the decoded json response.
stdClass Object(
[copied_adset_id] => 14848
[ad_object_ids] => Array
(
[0] => stdClass Object
(
[ad_object_type] => ad_set
[source_id] => 14848
[copied_id] => 448486
)
))
2
Answers
You could refactor it to use Collections since you are using Laravel.
For example:
The output of the above will be:
Here’s an example you can play around with.
Use following code hope this will help you