Hướng dẫn php xml to array
I know I'm 1 billion years late, but I had the same problem as you and needed a more complex solution, so here is a function ( The Disclaimer: I know it is easier to just use the PHP SimpleXML extension, but I needed to transform lots of XML files into JSON files for a big change in a project of mine. Also, the question is about how to transform XML to PHP arrays, not how to use XML in PHP.
Resuming all the documentation and comments, the function transforms attributes and elements values into simple array elements and uses a loop with itself to process elements which contain children. The arguments allow you to:
Usage example with your XML elements (I think you already solved it after 11 years, but I'm answering it, so...): test.xml
PHP
Output |