How To Convert XML To Associative Array in PHP

Today, We want to share with you How To Convert XML To Associative Array in PHP.In this post we will show you Parse XML into associative array using PHP, hear for Convert a SimpleXML object to associative array we will give you demo and example for implement.In this post, we will learn about Converting an XML Object to Associative Array in PHP with an example.

How To Convert XML To Associative Array in PHP

There are the Following The simple About How To Convert XML To Associative Array in PHP Full Information With Example and source code.

As I will cover this Post with live Working example to develop Convert Array to XML and XML to Array in PHP, so the XML into Associative Array using PHP for this example is following below.

Step 1: Sample XML file

  
  
      
        elc  
        15  
      
      
        school  
        20  
    
	  
        company  
        10  
    

Step 2: PHP Convert sample.xml File Into String

$product_xmlfile = file_get_contents($path);

Step 3: Convert string of XML into an Object

$product_obj= simplexml_load_string($product_xmlfile);

Step 4: PHP Encode XML Object Into JSON

$json  = json_encode($product_obj);

Step 5: PHP Decode Json Object

$results_data = json_decode($json, true);

PHP Full Source Code

$product_xmlfile = file_get_contents($path);
$product_obj= simplexml_load_string($product_xmlfile);
$json  = json_encode($product_obj);
$results_data = json_decode($json, true);
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about How To Convert XML To Associative Array in PHP.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment