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
🌐
Packagist
packagist.org › packages › spatie › array-to-xml
spatie/array-to-xml - Packagist
January 12, 2026 - 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. We highly appreciate you sending us a postcard from your hometown, mentioning ...
🌐
Packagist
packagist.org › packages › aivec › array-to-xml
aivec/array-to-xml - Packagist.org
March 4, 2020 - This package provides a very simple class to convert an array to an xml string. This is a fork of https://github.com/spatie/array-to-xml simply for compatibility with older versions of PHP.
🌐
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: ...
🌐
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 › vyuldashev › xml-to-array
vyuldashev/xml-to-array - Packagist.org
December 24, 2025 - pkg:composer/vyuldashev/xml-to-array · v1.1.0 2022-08-23 23:18 UTC · Requires · php: ^7.1|^8.0 · Requires (Dev) larapack/dd: ^1.1 · phpunit/phpunit: ^7.5|^9.5 · spatie/array-to-xml: ^2.7 · Suggests · None · Provides · None · Conflicts · None · Replaces · None ·
🌐
GitHub
github.com › spatie › array-to-xml › blob › main › README.md
array-to-xml/README.md at main · spatie/array-to-xml
![Tests](https://github.com/sp...https://packagist.org/packages/spatie/array-to-xml) · This package provides a very simple class to convert an array to an xml string....
Author   spatie
Find elsewhere
🌐
YOURLS
yourls.org › xref › includes › vendor › spatie › array-to-xml › README.md.source.html
PHPXRef 0.7.1 : YOURLS : /includes/vendor/spatie/array-to-xml/README.md source
1 2 [<img src="https://github-ads.s3.eu-central-1.amazonaws.com/support-ukraine.svg?t=1" />](https://supportukrainenow.org) 3 4 # Convert an array to xml 5 6 [![Latest Version](https://img.shields.io/github/release/spatie/array-to-xml.svg?style=flat-square)](https://github.com/spatie/array-to-xml/releases) 7 [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) 8 ![Tests](https://github.com/spatie/array-to-xml/workflows/Tests/badge.svg) 9 [![Total Downloads](https://img.shields.io/packagist/dt/spatie/array-to-xml.svg?style=flat-square)](https://packagist.org/packages/spatie/array-to-xml) 10 11 This package provides a very simple class to convert an array to an xml string.
🌐
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
🌐
Libraries.io
libraries.io › packagist › sammyjo20 › xml-to-array
sammyjo20/xml-to-array v1.0.0 on Packagist - Libraries.io
February 4, 2022 - This package provides an easy way to convert an XML string into an array. Inspired by Spatie's array-to-xml.
🌐
GitHub
github.com › spatie › array-to-xml › blob › main › composer.json
array-to-xml/composer.json at main · spatie/array-to-xml
"name": "spatie/array-to-xml", "description": "Convert an array to xml", "keywords": [ "convert", "array", "xml" ], "homepage": "https://github.com/spatie/array-to-xml", "license": "MIT", "authors": [ { "name": "Freek Van der Herten", "email": "freek@spatie.be", "homepage": "https://freek.dev", "role": "Developer" } ], "require": { "php" : "^8.0", "ext-dom": "*" }, "require-dev": { "mockery/mockery": "^1.6", "pestphp/pest": "^1.23 || ^2
Author   spatie
🌐
Packagist
packagist.org › packages › rene-roscher › array-to-xml
rene-roscher/array-to-xml - Packagist
August 21, 2019 - use Spatie\ArrayToXml\ArrayToXml; ... $array = [ 'Good guy' => [ 'name' => 'Luke Skywalker', 'weapon' => 'Lightsaber' ], 'Bad guy' => [ 'name' => 'Sauron', 'weapon' => 'Evil Eye' ] ]; $result = ArrayToXml::convert($array); After running this piece of code $result will contain: <?xml version="1.0"?> ...
🌐
Packagist
packagist.org › packages › sammyjo20 › xml-to-array
sammyjo20/xml-to-array - Packagist.org
February 4, 2022 - This package provides an easy way to convert an XML string into an array. Inspired by Spatie's array-to-xml.