Skip to content
Advertisement

PHP convert Array to XML

I have an array like so:

JavaScript

Now I am trying to covert this to XML exactly how this looks in the array, like Project should be a node with everything inside, Location should also be a node with everything inside the Location array inside that node, along with ContactInformation.

This is what I have:

JavaScript

but Project, Location and ContactInformation return as like so:

JavaScript

My question is how do I fix my XML Output?

Advertisement

Answer

Almost had it! You simply had to pass the $subnode, not $xml into the recursive call of function:

JavaScript

Output

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement