分享一个解析XML成为php数组的方法

时间:2023-03-09 03:13:03
分享一个解析XML成为php数组的方法

原文:分享一个解析XML成为php数组的方法

<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
$xml = 'site_1.xml';
$myxml = simplexml_load_file($xml);
// print_r($myxml); print_r(xmlToArray($myxml)); function xmlToArray($xml){
$arr_xml = (array)$xml;
foreach($arr_xml as $key=>$item){
if(is_object($item) || is_array($item)){
$arr_xml[$key] = xmlToArray($item);
}
}
return $arr_xml;
} ?>