Created
December 24, 2014 08:44
-
-
Save mul14/c0139e202b047dddc594 to your computer and use it in GitHub Desktop.
PHP - Convert array to 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
/** | |
* @param array $array | |
* @return \stdClass | |
* @internal param array $array | |
*/ | |
function convertArrayToObject(array $array) | |
{ | |
$object = new \stdClass; | |
foreach($array as $key => $value) | |
{ | |
if(strlen($key)) | |
{ | |
if(is_array($value)) | |
{ | |
$object->{$key} = convertArrayToObject($value); | |
} | |
else | |
{ | |
$object->{$key} = $value; | |
} | |
} | |
} | |
return $object; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment