<?php
print_r($response->response->docs);
?>
Outputs the following:
Array
(
[0] => Object
(
[_fields:private] => Array
(
[id]=>9093
[name]=>zahir
)
Object
(
[_fields:private] => Array
(
[id]=>9094
[name]=>hussain
)..
)
)
How can I convert this object to an array? I'd like to output the following:
Array
(
[0]=>
(
[id]=>9093
[name]=>zahir
)
[1]=>
(
[id]=>9094
[name]=>hussain
)...
)
Is this possible?
I had the same problem and I solved it with get_object_vars mentioned above.
Furthermore, I had to convert my object with json_decode and I had to iterate the array with the oldschool "for" loop (rather then for-each).
I ran into an issue with Andy Earnshaw's answer because I had factored this function out to a separate class within my application, "HelperFunctions", which meant the recursive call to objectToArray() failed.
I overcame this by specifying the class name within the array_map call like so:
I would have written this in the comments but I don't have enough reputation yet.
You should look at get_object_vars , as your properties are declared private you should call this inside the class and return its results.
Be careful, for primitive data types like strings it will work great, but I don't know how it behaves with nested objects.
in your case you have to do something like;
Try this:-