Created
July 31, 2014 15:48
-
-
Save nathanmac/fbd313ef9dfef8a48006 to your computer and use it in GitHub Desktop.
Convert an object to an array recursively
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 to and array recursively | |
* | |
* @param Object $object Object to be converted to an array | |
* | |
* @return array | |
*/ | |
private function _objectToArray($object) | |
{ | |
if(is_object($object)) $object = (array) $object; | |
if(is_array($object)) { | |
$new = array(); | |
foreach($object as $key => $val) { | |
$new[$key] = $this->_objectToArray($val); | |
} | |
} | |
else $new = $object; | |
return $new; | |
}//end _objectToArray() | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment