php json转为XML
程序员文章站
2022-07-15 13:10:09
...
function jsonToXML($source)
{
$string = "";
foreach ($source as $k => $v) {
$string .= "<" . $k . ">";
//判断是否是数组,或者,对像
if (is_array($v) || is_object($v)) {
//是数组或者对像就的递归调用
$string .= change($v);
} else {
//取得标签数据
$string .= $v;
}
$string .= "</" . $k . ">";
}
return $string;
}
例子:
$arr = [
'cc' => [
'in' => [
'AccNo' => '查询账号',
'BeginDate' => '开始时间',
'EndDate' => '截止日期',
'MinAmt' => '发生额下限',
'MaxAmt' => '发生额上限',
'BankType' => '',
'NextTag' => '查询下页标识',
'CurrType' => '001',
'DueBillNo' => ''
],
'dd' => ''
]
];
$str = jsonToXML($arr);
halt($str);
结果: