SimpleXMLElement转化数组——递归

代码如下:

	/**
	 * 递归转化SimpelXMLElement对象到数组
	 *
	 * @param unknown $xml_arr
	 */
	function convert_xml_to_arr($xml_arr){
		if($xml_arr instanceof SimpleXMLElement){
			$xml_arr = (array)$xml_arr;
		}
		foreach ($xml_arr as $key=>$val){
			if(($xml_arr[$key] instanceof SimpleXMLElement) || is_array($xml_arr[$key])){
				$xml_arr[$key]=$this->convert_xml_to_arr($xml_arr[$key]);
			}
		}
		return $xml_arr;
	}

Categories:

Updated: