Skip to content

Instantly share code, notes, and snippets.

@jaywilliams
Created December 16, 2009 04:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jaywilliams/257606 to your computer and use it in GitHub Desktop.
Save jaywilliams/257606 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;
}
?>
@neo85
Copy link

neo85 commented Sep 19, 2010

very nice function
gj

@mxdpeep
Copy link

mxdpeep commented Jan 20, 2011

or simillary METHOD inside a class :]

@delirehberi
Copy link

thanks for that jay :\

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment