"; foreach ($values as $key => $val) { if (is_array($val)) { $xml .= "<" . $key . ">" . $this->toXml($val) . ""; } else if (is_numeric($val)) { $xml .= "<" . $key . ">" . $val . ""; } else { $xml .= "<" . $key . ">"; } } $xml .= ""; return $xml; } /** * 将XML转为array * @param string $xml * @return mixed * @throws DtaException */ public function toArray(string $xml) { if (!$xml) { throw new DtaException('xml数据异常!'); } libxml_disable_entity_loader(true); return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); } }