Tuesday, 29 July 2014

PHP onject to array

Handy bit of PHP to convert and object to an array 
 
public function objectToArray($obj) 
{
    if(!is_array($obj) && !is_object($obj)) 
    return $obj;

    if(is_object($obj)) 
    $obj = get_object_vars($obj);

    return array_map(array($this, 'objectToArray'), $obj);
}

No comments:

Post a Comment