Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Sep 19, 2010

very nice function
gj

@mxdpeep

This comment has been minimized.

Copy link

commented Jan 20, 2011

or simillary METHOD inside a class :]

@delirehberi

This comment has been minimized.

Copy link

commented Nov 20, 2011

thanks for that jay :\

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.