### Decode the JSON String Into an Array

Finally, we’ve used the json_decode() function to decode the JSON string data. It’s important to note that we’ve passed TRUE in the second argument of the json_decode() function, which converts all objects into associative arrays.

Had you not passed TRUE in the second argument, the json_decode function would have produced objects of type StdClass instead of arrays.

So that's an outline of the whole process. Let’s run the simplexml.php file, and you should see the following output.

As expected, the array contains all the documents. As you may have noticed, it has also parsed the id field, which is attached with each document in the form of an attribute, and you can access it with the @attributes key, as shown in the above output. Basically, everything is available in the form of key-value pairs. So you have a complete array at your disposal for further processing.

So that’s how you can convert XML content into an array in PHP. It was a very simple example, but it should give you some insight into the whole process.

## Conclusion

In this article, we discussed how to convert an XML file into an array using PHP and SimpleXML. The SimpleXML extension is really useful when it comes to parsing and manipulating XML documents.

## The Best PHP Scripts on CodeCanyon

The free libraries on Packagist are wonderful for basic functionality—the foundation for a good app. However, for more specialized features or for complete applications that you can use and customize, take a look at the professional PHP scripts on CodeCanyon.

Explore thousands of the best and most useful PHP scripts ever created on CodeCanyon.

Here are a few of the best-selling and up-and-coming PHP scripts available on CodeCanyon for 2020.

## Learn PHP With a Free Online Course

If you want to learn PHP, check out our free online course on PHP fundamentals!

In this course, you'll learn the fundamentals of PHP programming. You'll start with the basics, learning how PHP works and writing simple PHP loops and functions. Then you'll build up to coding classes for simple object-oriented programming (OOP).

Along the way, you'll learn all the most important skills for writing apps for the web: you'll get a chance to practice responding to GET and POST requests, parsing JSON, authenticating users, and using a MySQL database.