PHP array to xml
<?php
define(‘NODE_FORMATE‘, "<%s>%s</%s>");
$testXml = array(
‘SubscribeToVSOPReq‘ => array(
‘ActionType‘ => ‘0‘,
‘OrderId‘ => ‘100000003800000000000000000001‘,
‘UserIDType‘ => ‘0‘,
‘ProductNo‘ => ‘18999999‘,
‘ProductOfferInfo‘ => array(
‘ProductOfferType‘ => ‘0‘,
‘ProductOfferID‘ => ‘123123‘,
‘VSubProdInfo‘ => array(‘VProductID‘ => ‘1350000000000000002130‘),
‘IsExperience‘ => 0,
‘SubscribeType‘ => 0,
),
)
);
function buildXML($arrXML)
{
$res = "";
foreach ($arrXML as $node => $value) {
if (is_array($value)) {
$value = buildXML($value);
}
$res .= sprintf(NODE_FORMATE, $node, $value, $node);
}
return $res;
}
var_dump(buildXML($testXml));
?>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。