Skip to content

Instantly share code, notes, and snippets.

@mul14
Created December 24, 2014 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mul14/c0139e202b047dddc594 to your computer and use it in GitHub Desktop.
Save mul14/c0139e202b047dddc594 to your computer and use it in GitHub Desktop.
PHP - Convert array to object
/**
* @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