/**
* xml文档转为数组元素
* @param obj $xmlobject XML文档对象
* @return array
*/
public static function arrayToXml($data, $dom = null){
if (empty($dom)) {
$dom = new DOMDocument('1.0', 'UTF-8');
}
if (is_array($data)) {
foreach ($data as $key => $value) {
$child = new DOMElement(is_int($key) ? 'item' : $key);
$dom->appendChild($child);
self::arrayToXml($value, $child);
}
} else {
$dom->appendChild(new DOMText($data));
}
if ($dom instanceof DOMDocument) {
return $dom->saveXML();
}
return null;
}