function sxml2arr($xml) { $arr = (array)$xml; foreach ($arr as $key => $value) { if($value instanceof simplexmlElement || is_array($value)) { $arr[$key] = sxml2arr($value); } } return $arr; }
function arr2xml($arr,$node=NULL) { if($node === NULL) { $xml = new simplexmlElement("<?xml version='1.0' encoding='utf-8'?><geng></geng>"); } else { $xml = $node; } foreach ($arr as $key => $value) { if(is_array($value)) { if(is_numeric($key)) { arr2xml($value,$xml->addChild('item'.$key)); } else { arr2xml($value,$xml->addChild($key)); } } else if(is_numeric($key)) { $xml->addChild('item'.$key,$value); }else { $xml->addChild($key,$value); } } return $xml; }原文链接:https://www.f2er.com/xml/299949.html