Converting PHP Object to Associative Array
When integrating APIs that utilize objects and your code employs arrays, the need to convert one to the other arises. For this purpose, a simple and efficient solution is to typecast the object to an array like this:
$array = (array) $yourObject;
This quick and dirty method will result in an array with keys as member variable names and values as the corresponding object properties. Notable exceptions include inaccessible integer properties, prefixed protected variables ('*'), and prefixed private variables ('
The above is the detailed content of How Do I Efficiently Convert a PHP Object to an Associative Array?. For more information, please follow other related articles on the PHP Chinese website!