xml转array
/** * @Notes: xml转array * @Interface xmlToArray * @param $xml * @return mixed * @author: masonzhang * @Time: 2023/05/19 14:30 */ public function xmlToArray($xml): array { return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); }
array转xml
/** * @Notes: array转xml * @Interface arrayToXml * @param $arr * @return string * @author: masonzhang * @Time: 2023/05/19 14:30 */ public function arrayToXml($arr): string { $xml = "<xml>"; foreach ($arr as $key=>$val){ if (is_numeric($val)){ $xml.="<".$key.">".$val."</".$key.">"; } else { $xml.="<".$key.">".$val."</".$key.">"; } $xml.="</xml>"; return $xml; } }