Skip to content

Instantly share code, notes, and snippets.

@chucktrukk
Forked from jaywilliams/array_to_object.php
Created September 23, 2010 19:31
Show Gist options
  • Save chucktrukk/594195 to your computer and use it in GitHub Desktop.
Save chucktrukk/594195 to your computer and use it in GitHub Desktop.
<?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 array2obj($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