Skip to content

Instantly share code, notes, and snippets.

@dmitrymomot
Forked from jaywilliams/array_to_object.php
Created October 19, 2012 19:18
Show Gist options
  • Save dmitrymomot/3920125 to your computer and use it in GitHub Desktop.
Save dmitrymomot/3920125 to your computer and use it in GitHub Desktop.
Convert a multi-dimensional array into a stdClass object. Pass by reference.
<?php
/**
* Convert a multi-dimensional array into a stdClass object.
*
* Example:
* $values = array('hello'=>'world');
*
* // Convert the array to an object
* array_to_object($values);
*
* echo $values->hello;
*
* @param array $array The input array
* @return object
*/
function array_to_object($array)
{
return is_array($array) ? (object) array_map(__FUNCTION__,$array) : $array;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment