php xml to array

/**
 *  @method:xml to array
 *  @param : simplexml $xml
 *  @author:taylor
 */
$xml = simplexml_load_string($xmlstring);
function xmltoarray($object, &$tmparr=array()) 
{
    if (is_object($object)) 
    {
        $tmparr = get_object_vars($object);
    }
    foreach ($tmparr as $k => $v) 
    {
        if (is_array($v)) 
        {
            $tmparr[$k] = xmltoarray($v, $tmparr[$k]);
        } 
        elseif (is_object($v)) 
        {
            $tmparr[$k] = xmltoarray($v, $tmparr[$k]);
        } 
        else 
        {
            $tmparr[$k] = $v;
        }
    }
    return $tmparr;
}