

Here, tag is used to print the array in a formatted way. If no error exists in the XML content, then no error will be shown by the following script. Next, json_encode() and json_decode() function are used to get the associative array after converting the XML file content. Here, the courses.xml file is used for conversion that was created before. The following script shows the uses of file_get_contents() and simplexml_load_string() functions to create XML object. Example-1: Convert XML file content into an associative array without checking error

So, a two-dimensional associative array will generate after converting the following XML file into a PHP array. The file contains child elements under a parent element.

Create an XML file named courses.xml with the following content and store it in the location where the PHP script is. You will be required to create an XML file or define XML data in the script to know the way in converting XML data into an associative PHP array. It takes the JSON object variable as an argument. It returns the associative PHP array by converting JSON data. It takes the XML object variable as an argument. It returns the JSON object by converting the XML object. It takes the XML content value as an argument. It is used to create an XML object from XML data. It takes the XML file name as an argument. This function returns the XML object by converting XML file content. This function returns the XML object by converting the XML string data. It takes any XML file name as an argument. This function returns the string data by converting any XML data. The purposes of different functions are explained below. Some built-in functions are used to convert the XML content into an associative PHP array. How the XML document can be parsed and stored into an associative array is shown in this tutorial. The data from the XML document can be easily accessed and used in any web application using a PHP script. Using XML is the better solution to store a small amount of data when you don’t want to use any database for storing data. Every tag of this language is user-defined. It is different from other markup languages. XML (Extensible Markup Language) is one type of markup language that is used to store the data in a human-readable format.
