title: Convert JSON to XML in PHP, but create a container element in XML for JSON array
body: <p><em>Before I begin, I have read many posts/topics here/on the internet, but as far as I understand, I think none of the solutions I saw can deal with this JSON</em></p>
  <hr />
  <p>I have a JSON file which I am looking to convert into an XML file - the catch is, when converting to XML normally, JSON like this -</p>
  <pre><code>{
      &quot;data&quot;: {
          &quot;key4&quot;:{
              &quot;sample8&quot;: [
                  {
                      &quot;sample9&quot;:&quot;val&quot;,
                      &quot;sample10&quot;:&quot;val&quot;
                  },
                  {
                      &quot;sample11&quot;:&quot;val&quot;,
                      &quot;sample12&quot;:&quot;val&quot;
                  },
                  {
                      &quot;sample13&quot;:&quot;val&quot;,
                      &quot;sample14&quot;:&quot;val&quot;
                  }
              ]
          }
      }
  }
  </code></pre>
  <p>becomes -</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot;?&gt;
  &lt;data&gt;
      &lt;key4&gt;
          &lt;sample8&gt;
              &lt;sample9&gt;val&lt;/sample9&gt;
              &lt;sample10&gt;val&lt;/sample10&gt;
          &lt;/sample8&gt;
          &lt;sample8&gt;
              &lt;sample11&gt;val&lt;/sample11&gt;
              &lt;sample12&gt;val&lt;/sample12&gt;
          &lt;/sample8&gt;
          &lt;sample8&gt;
              &lt;sample13&gt;val&lt;/sample13&gt;
              &lt;sample14&gt;val&lt;/sample14&gt;
          &lt;/sample8&gt;
      &lt;/key4&gt;
  &lt;/data&gt;
  </code></pre>
  <p>But, what I am looking to do is create a container element in the XML for every JSON array, with a specific array item element name (like &quot;item&quot;). Here's an example of the XML result I want -</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot;?&gt;
  &lt;data&gt;
      &lt;key4&gt;
          &lt;sample8&gt;
              &lt;item&gt;
                  &lt;sample9&gt;val&lt;/sample9&gt;
                  &lt;sample10&gt;val&lt;/sample10&gt;
              &lt;/item&gt;
              &lt;item&gt;
                  &lt;sample11&gt;val&lt;/sample11&gt;
                  &lt;sample12&gt;val&lt;/sample12&gt;
              &lt;/item&gt;
              &lt;item&gt;
                  &lt;sample13&gt;val&lt;/sample13&gt;
                  &lt;sample14&gt;val&lt;/sample14&gt;
              &lt;/item&gt;
          &lt;/sample8&gt;
      &lt;/key4&gt;
  &lt;/data&gt;
  </code></pre>
  <p>How do I do this? As I said, I've tried many different things but nothing seems to work out for me... Kindly guide :) Thanks!</p>
  <hr />
  <p><strong>P.S.</strong> If PHP doesn't support this kind of conversion, I'll be okay to use any other language which supports doing something like this. </p>