I'm integrating an API to my website which works with data stored in objects while my code is written using arrays.
I'd like a quick and dirty function to convert an object to an array.
I'm integrating an API to my website which works with data stored in objects while my code is written using arrays.
I'd like a quick and dirty function to convert an object to an array.
If your object properties are public you can do:
If they are private or protected, they will have weird key names on the array. So, in this case you will need the following function:
This answer is only the union of the different answers of this post, but it's the solution to convert a PHP object with public or private properties with simple values or arrays in associative array ...
this function can convert object proprity to array associatif
use >= php5
By using typecasting you can resolve your problem. Just add following lines to your return object :
you can also add new key and value pair to it by using:
Hi,
Here is my recursive PHP function to convert PHP objects to an associative array
Usage example:
Type cast your object to an array.
It will solve your problem.