Convert XML to JSON in PHP

In this short article, we’ll explain to you how to convert XML to JSON in PHP. We can easily use the JSON format instead of XML. So we prefer to use JSON format.

Let’s take an example where we will try to convert the following xml code as below.

We can get the PHP array by calling json_decode() function as below.

Using foreach loop we can iterate each element of the associative array.

That’s it for today.
Thank you for reading. Happy Coding..!!

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *