Saturday 1 February 2014

Convert a PHP Object to an Array

Following function has easily to convert an associative array from object data


function object_to_array($result) 
{ 
    $arraydata = array(); 
    foreach ($result as $key=>$value) 
    { 
        if (is_object($value)) 
        { 
            $arraydata [$key]=object_to_array($value); 
        } 
        elseif (is_array($value)) 
        { 
            $arraydata [$key]=object_to_array($value); 
        } 
        else 
        { 
            $arraydata [$key]=$value; 
        } 
    } 
    return $arraydata ; 
}  

No comments:

Post a Comment