I have this array ($data):
Array (
[status_code] => X
[key_1] => 12345
[key_2] => 67890
[short_message] => test
[long_message] => test_long_message
)
But I am struggling to convert this to an XML element.
Here is my code:
$xml = new SimpleXMLElement('<root/>');
array_walk_recursive($data, array ($xml, 'addChild'));
print $xml->asXML();
Here is the results I am wanting:
<root>
<status_code>X</status_code>
<key_1>12345</key_1>
<key_2>67890</key_2>
<short_message>test</short_message>
<long_message>test_long_message</long_message>
</root>
Instead I get:
<X>1234567890testtest_message_long
Could somebody please point out what I am doing wrong?
Thanks,
Peter