How to convert XML to Array or Object in PHP

Code Snippet: XML to Array in PHP The article explores how to convert XML to array or object in PHP. Here’s a snippet from the article. <?php $courses_xml = '<courses> <course> <title>Fundamentals of Programming</title> <credithours>3 + 1</credithours> <prerequisites>None</prerequisites> </course> <course> <title>Object Oriented Programming</title> <credithours>3 + 1</credithours> <prerequisites>Fundamentals of Programming</prerequisites> </course> </courses>'; $xml = simplexml_load_string($courses_xml); $json = json_encode($xml, JSON_PRETTY_PRINT); $array = json_decode($json, true); ?> That’s just one way of going about this problem. Learn more about this topic in the following sections. Relevant Content: JSON to XML Conversion The article “How to convert XML to JSON in PHP” sets a solid foundation for XML to array in PHP. We suggest reading that article as this article borrows alot from it. We will see that the existing solution adds only one extra function call to get an array or object, and the rest of the code is similar. So without any further…