Created
March 28, 2012 21:53
-
-
Save zorbash/2230896 to your computer and use it in GitHub Desktop.
php object to array function to be used before json encoding of a class
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
function object_to_array($object, $utf_encode=FALSE) | |
{ | |
if(is_array($object) || is_object($object)) | |
{ | |
$array = array(); | |
foreach($object as $key => $value) | |
{ | |
$value = object_to_array($value, $utf_encode); | |
if($utf_encode && is_string($value)){ | |
$value = utf8_encode($value); | |
} | |
$array[$key] = $value; | |
} | |
return $array; | |
} | |
return $object; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment