Skip to main content

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;
}
?>