A php class that converts multidimensional arrays to xml.
It supports regular nodes, repeating node tags, attributes
namespaces, cdata sections, and all you should need when building an xml data structure.
composer require fracalo/arr2xml
use Fracalo\Arr2Xml\Arr2Xml;
$payload = [
'_nodeName' => 'root',
'_val' => [
[
'_nodeName' => 'items',
'_val' => [
[
'_nodeName' => 'item',
'_val' => 'Computer'
],
[
'_nodeName' => 'item',
'_val' => 'Keyboard'
],
[
'_nodeName' => 'item',
'_val' => 'Mouse'
],
[
'_nodeName' => 'item',
'_val' => 'Monitor'
],
]
]
]
];
$x = new Arr2Xml('1.0', 'UTF-8');
$xml = $x->convert($payload);
<?xml version="1.0" encoding="UTF-8"?>
<root>
<items>
<item>Computer</item>
<item>Keyboard</item>
<item>Mouse</item>
<item>Monitor</item>
</items>
</root>