PHP将数组转换为XML ; 函数ArrayToXml()

function arrayToXml($arr,$dom=0,$item=0)
{
if (!$dom) {
$dom = new DOMDocument("1.0");
}
if (!$item) {
$item = $dom->createElement("root");
$dom->appendChild($item);
}
foreach ($arr as $key => $val) {
$itemx = $dom->createElement(is_string($key) ? $key : "item");
$item->appendChild($itemx);
if (!is_array($val)) {
$text = $dom->createTextNode($val);
$itemx->appendChild($text);

} else {
$this->arrayToXml($val, $dom, $itemx);
}
}
return $dom->saveXML();
}
原文地址:https://www.cnblogs.com/haoxuanchen2014/p/14873231.html