title: How do I Convert jSON to XML
body: <p>Before I begin, I know there are a bunch of questions similar to this, but trust me, I read all, if not most of them. I tried a bunch of solutions, but none of them seem to work. I'm getting a blank &quot;tree&quot; as my result. Here is the code that I am using.</p>
  <pre class="lang-php prettyprint-override"><code>$jSON = json_decode('array here');
  
  function array2xml($array, $xml = false)
  {
      if($xml === false) {
          $xml = new SimpleXMLElement('&lt;result/&gt;');
      }
  
      foreach($array as $key =&gt; $value) {
          if(is_array($value)) {
              array2xml($value, $xml-&gt;addChild($key));
          } else {
              $xml-&gt;addChild($key, $value);
          }
      }
  
      return $xml-&gt;asXML();
  }
  </code></pre>
  <p>Here is the jSON array that I'm using.</p>
  <p><a href="http://pastebin.com/pN3QwSHU" rel="nofollow noreferrer">http://pastebin.com/pN3QwSHU</a></p>
  <p>I'm not sure why it isn't working. Here is the result when I use that function.</p>
  <pre><code>&lt;result&gt;
  &lt;generated_in&gt;155ms&lt;/generated_in&gt;
  &lt;/result&gt;
  </code></pre>