<?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));
?>
PHP array to xml,布布扣,bubuko.com
原文:http://my.oschina.net/u/249000/blog/294556