php代码 数组转xml
程序员文章站
2024-03-14 13:54:46
...
//生成xml格式数据
public function ToXml($array)
{
if (!is_array($array) || count($array) <= 0) {
return;
}
$xml = '<xml version="1.0">';
foreach ($array as $key => $val) {
if (is_numeric($val)) {
$xml .= "<" . $key . ">" . $val . "</" . $key . ">";
} else {
$xml .= "<" . $key . "><![CDATA[" . $val . "]]></" . $key . ">";
}
}
$xml .= "</xml>";
return $xml;
}