php xml 转成 数组

/**
     * xml 转换成数组
     * @param type $xml
     * @return type
     */
     public function xml_to_array($xml)
    {
        $array = (array)(simplexml_load_string($xml));         
        foreach ($array as $key=>$item)
        { 
            $array[$key]  = $this->struct_to_array((array)$item);
        }
        return $array;   
    }
     public function struct_to_array($item) {                        
        if(!is_string($item)) {                                
          $item = (array)$item;                                
          foreach ($item as $key=>$val){                       
            $item[$key]  = $this->struct_to_array($val);             
          }                                                    
        }                                                      
        return $item;                                          
    }


你可能感兴趣的:(php xml 转成 数组)