PHPackages                             vaclavvanik/xml-to-array - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. vaclavvanik/xml-to-array

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

vaclavvanik/xml-to-array
========================

Convert xml to array

1.3.0(4y ago)02.8kMITPHPPHP ^7.3 || ^8.0CI failing

Since Sep 1Pushed 4y ago1 watchersCompare

[ Source](https://github.com/vaclavvanik/xml-to-array)[ Packagist](https://packagist.org/packages/vaclavvanik/xml-to-array)[ Docs](https://github.com/vaclavvanik/xml-to-array)[ RSS](/packages/vaclavvanik-xml-to-array/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (5)Used By (0)

Convert xml to array
====================

[](#convert-xml-to-array)

This package provides a very simple class to convert xml to array.

Install
-------

[](#install)

You can install this package via composer.

```
composer require vaclavvanik/xml-to-array
```

Usage
-----

[](#usage)

```
use VaclavVanik\XmlToArray\XmlToArray;

$xml =
        Staff

        Sauron
        Evil Eye

XML;

$result = XmlToArray::stringToArray($xml);
```

After running this piece of code `$result` will contain:

```
[
    'root' => [
        'good_guy' => [
            [
                'name' => 'Luke Skywalker',
                'weapon' => 'Lightsaber',
            ],
            [
                'name' => 'Gandalf',
                'weapon' => 'Staff',
            ],
        ],
        'bad_guy' => [
            '@attributes' => [
                'lang' => 'Black Speech',
            ],
            'name' => 'Sauron',
            'weapon' => 'Evil Eye',
        ],
    ],
];
```

Converting XML file is also available:

```
use VaclavVanik\XmlToArray\XmlToArray;

$result = XmlToArray::stringToArray('my.xml');
```

Converting DOMDocument directly:

```
use DOMDocument;
use VaclavVanik\XmlToArray\XmlToArray;

$doc = new DOMDocument();
//$doc->loadXML(...);

$xmlToArray = new XmlToArray($doc);
$result = $xmlToArray->toArray();
```

Run check - coding standards and php-unit
-----------------------------------------

[](#run-check---coding-standards-and-php-unit)

```
make check
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~238 days

Total

4

Last Release

1734d ago

PHP version history (2 changes)1.0.0PHP ^7.3

1.1.0PHP ^7.3 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3754860?v=4)[Václav Vaník](/maintainers/vaclavvanik)[@vaclavvanik](https://github.com/vaclavvanik)

---

Top Contributors

[![vaclavvanik](https://avatars.githubusercontent.com/u/3754860?v=4)](https://github.com/vaclavvanik "vaclavvanik (19 commits)")

---

Tags

xmlarrayconvert

### Embed Badge

![Health badge](/badges/vaclavvanik-xml-to-array/health.svg)

```
[![Health](https://phpackages.com/badges/vaclavvanik-xml-to-array/health.svg)](https://phpackages.com/packages/vaclavvanik-xml-to-array)
```

###  Alternatives

[openlss/lib-array2xml

Array2XML conversion library credit to lalit.org

31052.5M47](/packages/openlss-lib-array2xml)[clearstream/xml-to-array

Incredibly simple XML to array PHP converter

6736.7k](/packages/clearstream-xml-to-array)[digitickets/lalit

GitHub copy of LaLit's XML2Array and Array2XML

721.3M6](/packages/digitickets-lalit)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
