How can I convert an array to a SimpleXML object in PHP?
a short one:
'blub',
'foo' => 'bar',
'another_array' => array (
'stack' => 'overflow',
),
);
$xml = new SimpleXMLElement(' ');
array_walk_recursive($test_array, array ($xml, 'addChild'));
print $xml->asXML();
results in
bla
foo
stack
keys and values are swapped - you could fix that with array_flip()
before the array_walk. array_walk_recursive
requires PHP 5. you could use array_walk
instead, but you won't get 'stack' => 'overflow'
in the xml then.