Its easy with the below package, Just install the package via composer :

https://github.com/spatie/array-to-xml

The implementation will be :

$array= 'invoice' => [
    'date' => date('Y-m-d H:i:s'),
    'due_date' => date('Y-m-d H:i:s'),
    'client' => ['name' => 'John', 'code' => ''],
    'items' => [
        'item' => [
            'name' => 'reg1',
            'description' => 'reg1 on evt',
            'unit_price' => '10',
            'quantity' => '1.0'
        ],
        'item' => [
            'name' => 'reg1',
            'description' => 'reg1 on evt',
            'unit_price' => '10',
            'quantity' => '1.0'
        ]
    ]
]

And then :

$result = ArrayToXml::convert($array);

Don't forget to include use Spatie\ArrayToXml\ArrayToXml; at the top of the class/Controller.

Answer from Gammer on Stack Overflow
🌐
GitHub
github.com › spatie › array-to-xml
GitHub - spatie/array-to-xml: A simple class to convert an array to xml · GitHub
This package provides a very simple class to convert an array to an xml string. We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
Starred by 1.2K users
Forked by 214 users
Languages   PHP
🌐
Packagist
packagist.org › packages › spatie › array-to-xml
spatie/array-to-xml - Packagist
January 12, 2026 - To add attributes to the root element provide an array with an _attributes key as the second argument. The root element name can then be set using the rootElementName key. $result = ArrayToXml::convert($array, [ 'rootElementName' => 'helloyouluckypeople', '_attributes' => [ 'xmlns' => 'https://github.com/spatie/array-to-xml', ], ], true, 'UTF-8');
🌐
GitHub
github.com › spatie › array-to-xml › blob › main › README.md
array-to-xml/README.md at main · spatie/array-to-xml
A simple class to convert an array to xml. Contribute to spatie/array-to-xml development by creating an account on GitHub.
Author   spatie
🌐
GitHub
github.com › spatie › array-to-xml › blob › main › src › ArrayToXml.php
array-to-xml/src/ArrayToXml.php at main · spatie/array-to-xml
A simple class to convert an array to xml. Contribute to spatie/array-to-xml development by creating an account on GitHub.
Author   spatie
🌐
GitHub
github.com › spatie › array-to-xml › blob › main › CHANGELOG.md
array-to-xml/CHANGELOG.md at main · spatie/array-to-xml
A simple class to convert an array to xml. Contribute to spatie/array-to-xml development by creating an account on GitHub.
Author   spatie
🌐
Stack Overflow
stackoverflow.com › questions › 41020242 › convert-complexe-arrays-to-xml-laravel
Convert Complexe arrays to XML Laravel - Stack Overflow
I'm building a Web Service where user receive data depending on the format desired (Json/Xml), Making Json response is not the problem , I get multiple arrays from an operation and i should return it to the user as Xml. when there is only one array i can do it using this bundle spatie\array-to-xml\ ...
🌐
GitHub
github.com › spatie › array-to-xml › releases
Releases · spatie/array-to-xml
A simple class to convert an array to xml. Contribute to spatie/array-to-xml development by creating an account on GitHub.
Author   spatie
Find elsewhere
🌐
GitHub
github.com › spatie › array-to-xml › network
Network Graph · spatie/array-to-xml
A simple class to convert an array to xml. Contribute to spatie/array-to-xml development by creating an account on GitHub.
Author   spatie
🌐
GitHub
github.com › spatie › array-to-xml › watchers
Watchers · spatie/array-to-xml
A simple class to convert an array to xml. Contribute to spatie/array-to-xml development by creating an account on GitHub.
Author   spatie
🌐
GitHub
github.com › spatie › array-to-xml › discussions › 191
XML to array · spatie/array-to-xml · Discussion #191
I suspect I am missing something obvious seeing as I thought there would be others asking about this feature... I really like the Spatie conventions used to convert array to XML (eg. _attributes, _...
Author   spatie
🌐
Scrutinizer-ci
scrutinizer-ci.com › g › spatie › array-to-xml
Code Quality Summary - spatie/array-to-xml - Measure and Improve Code Quality continuously with Scrutinizer
Please ask an admin of your repository to re-new the access token on this website. ... Inspected Add support for dropping XML d... ... Inspected Add support for custom keys (#... ... Inspected Feature/102 DOM Properties (#1... ... Inspected Fixes #88: Adds numeric array...
🌐
Packagist
packagist.org › packages › dmb › xml-converter
dmb/xml-converter - Packagist
A package that allows you to easily convert your XML string into array format or generate an XML string from an array. github.com/davidemariabusi/xml-converter · Homepage · Source · Issues · Installs: 314 · Dependents: 0 · Suggesters: 0 · Security: 0 · Stars: 0 · Watchers: 1 · Forks: ...
🌐
Augsburg
go.augsburg.edu › includes › vendor › spatie › array-to-xml
Index of /includes/vendor/spatie/array-to-xml
Index of /includes/vendor/spatie/array-to-xml · Name Last modified Size Description · Parent Directory - README.md 2021-03-06 12:09 12K src/ 2021-03-06 12:09 - · Apache Server at go.augsburg.edu Port 80
🌐
GitHub
github.com › ashenwolf › array-to-xmlfile
GitHub - ashenwolf/array-to-xmlfile: A simple class to convert an array to xml using XmlWriter compatible with array-to-xml
This package provides a very simple class to convert an array to an xml string. You can install this package via composer. ... use Spatie\ArrayToXml\ArrayToXml; ...
Author   ashenwolf