Last active
October 26, 2022 08:10
-
-
Save peshi/8902621 to your computer and use it in GitHub Desktop.
Convert multidimensional stdClass object(s) to array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Convert multidimensional stdClass object(s) to array | |
* | |
* @param $object | |
* @return array | |
*/ | |
private function objectToArray($object) { | |
if (is_object($object)) { | |
$object = get_object_vars($object); | |
} | |
if (is_array($object)) { | |
return array_map(array($this, 'objectToArray'), $object); | |
} else { | |
return $object; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You would receive the same result if you encode your object(s) to json and decode it.