Last active
October 20, 2016 09:33
-
-
Save TeslaCrest/fa7182bb2a723506fa9393bd33a2a69a to your computer and use it in GitHub Desktop.
Convert an object into an array (by example json object)
This file contains 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 an object into an array (by example json object) | |
* @param an object | |
* @return an array | |
*/ | |
function objectToArray($object) { | |
if(is_object($object)) { | |
$object = get_object_vars($object); | |
} | |
if(is_array($object)) { | |
// Retourne un nouvel array | |
return array_map(__FUNCTION__, $object); | |
} | |
else { | |
return $object; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment