How can I convert an array to a SimpleXML object in PHP?
function array2xml($array, $xml = false){
if($xml === false){
$xml = new SimpleXMLElement('<'.key($array).'/>');
$array = $array[key($array)];
}
foreach($array as $key => $value){
if(is_array($value)){
$this->array2xml($value, $xml->addChild($key));
}else{
$xml->addChild($key, $value);
}
}
return $xml->asXML();
}