共计 303 个字符,预计需要花费 1 分钟才能阅读完成。
<?php
$test_array = array ('bla' => 'blub',
'foo' => 'bar',
'another_array' => array ('stack' => 'overflow',
),
);
$xml = new SimpleXMLElement('<root/>');
array_walk_recursive($test_array, array ($xml, 'addChild'));
print $xml->asXML();
输出结果:
<?xml version="1.0"?>
<root>
<blub>bla</blub>
<bar>foo</bar>
<overflow>stack</overflow>
</root>
正文完