Return to Snippet

Revision: 56342
at March 22, 2012 22:25 by satie83


Initial Code
function object_to_array($data)
{
    if(is_array($data) || is_object($data))
    {
        $result = array();
        
        foreach($data as $key => $value) {
            $result[$key] = $this->object_to_array($value);
        }

        return $result;
    }
    
    return $data;
}

Initial URL
http://codesnippets.joyent.com/posts/show/1641

Initial Description
Converts a php object to an associative array

Initial Title
PHP - Convert an object to an associative array

Initial Tags
php, object, array

Initial Language
PHP