convert a array to xml
<p>I want to convert a php array to xml.</p>

<p>I have this code:</p>

<pre><code>$output=array("result" =&gt; "this is the result");

print assocArrayToXML("example",$output);


function assocArrayToXML($root_element_name,$ar) {

     $xml = new SimpleXMLElement("&lt;?xml version=\"1.0\"?&gt;&lt;{$root_element_name}&gt;&lt;/{$root_element_name}&gt;");

     $f = create_function('$f,$c,$a','
        foreach($a as $k=&gt;$v) {
                   if(is_array($v)) {
            $ch=$c-&gt;addChild($k);
            $f($f,$ch,$v);
        } else {
            $c-&gt;addChild($k,$v);
        }
    }');
    $f($f,$xml,$ar);
    return $xml-&gt;asXML();
    }
</code></pre>

<p>I found the function here:</p>

<p><a href="http://php.net/manual/es/book.simplexml.php" rel="nofollow">http://php.net/manual/es/book.simplexml.php</a></p>

<p>When I execute the code, I got this:</p>

<pre><code>this is the result
</code></pre>

<p>Why can't I see the xml? is it because it is malformed? or maybe the mozilla firefox doesn't write it?</p>
