Return to Snippet

Revision: 55006
at January 21, 2012 05:36 by gabrielsmith


Initial Code
function arrayToObject($array) {
    if(!is_array($array)) {
        return $array;
    }
    
    $object = new stdClass();
    if (is_array($array) && count($array) > 0) {
      foreach ($array as $name=>$value) {
         $name = strtolower(trim($name));
         if (!empty($name)) {
            $object->$name = arrayToObject($value);
         }
      }
      return $object; 
    }
    else {
      return FALSE;
    }
}

Initial URL
http://www.richardcastera.com/blog/php-convert-array-to-object-with-stdclass

Initial Description
Converts multi-dimensional array to stdClass

Initial Title
Array to Object

Initial Tags


Initial Language
PHP