How can I convert an array to a SimpleXML object in PHP?
From PHP 5.4
function array2xml($data, $root = null){ $xml = new SimpleXMLElement($root ? '<' . $root . '/>' : ''); array_walk_recursive($data, function($value, $key)use($xml){ $xml->addChild($key, $value); }); return $xml->asXML(); }