PHPackages                             vhood/tree-converter - 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. vhood/tree-converter

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

vhood/tree-converter
====================

tree structure type switcher

1.1.0(3y ago)14661BSD-2-ClausePHPPHP &gt;=5.6CI failing

Since Mar 23Pushed 2y ago1 watchersCompare

[ Source](https://github.com/vhood/php-tree-converter)[ Packagist](https://packagist.org/packages/vhood/tree-converter)[ RSS](/packages/vhood-tree-converter/feed)WikiDiscussions main Synced 4w ago

READMEChangelogDependencies (1)Versions (15)Used By (0)

PHP Tree Type Converter
=======================

[](#php-tree-type-converter)

[![tests](https://camo.githubusercontent.com/c5335ca231742302dffde91f9622acfd782f61d66bb835897b742b5803c02b13/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f76686f6f642f7068702d747265652d636f6e7665727465722f72656c656173652e796d6c)](https://github.com/vhood/php-tree-converter/actions/workflows/release.yml)[![version](https://camo.githubusercontent.com/1958c995e6afa1bd12ec73ba781c74fb5d23d40f787a2e17a7fbbc4e03fc2aeb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f76686f6f642f747265652d636f6e766572746572)](https://packagist.org/packages/vhood/tree-converter)[![downloads](https://camo.githubusercontent.com/1a7824df4cd430e50d16dd0aaea143ef7dd85805ac9913da395bb80ac7659186/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f76686f6f642f747265652d636f6e766572746572)](https://packagist.org/packages/vhood/tree-converter)[![license](https://camo.githubusercontent.com/564a4f4c0c07895eea0245de81c4e1421179afaa9c8cbc1354e7503c6884fbc0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f76686f6f642f7068702d747265652d636f6e766572746572)](/LICENSE)

This package based on native php arrays allows you to switch a tree type.

Supported types:

- Adjacency list
- Materialized path
- Nested set
- Associative array trees

See **[data examples](/tests/_data/)**

Installation
------------

[](#installation)

```
composer require vhood/tree-converter
```

Requirements
------------

[](#requirements)

- php &gt;=5.6

Usage
-----

[](#usage)

Usage example:

```
use Vhood\TreeType\Converter;
use Vhood\TreeType\Type\AdjacencyList;

$adjacencyList = [
    [
        'id' => 1,
        'name' => 'node1',
        'parent_id' => null,
    ],
    [
        'id' => 2,
        'name' => 'node2',
        'parent_id' => 1,
    ],
];

$adjacencyListConverter = new Converter(new AdjacencyList($adjacencyList));

print_r($adjacencyListConverter->toAssociativeArrayTree('children', 'id'));

// Array
// (
//     [0] => Array
//         (
//             [id] => 1
//             [name] => node1
//             [children] => Array
//                 (
//                     [0] => Array
//                         (
//                             [id] => 2
//                             [name] => node2
//                             [children] => Array
//                                 (
//                                 )

//                         )

//                 )

//         )

// )
```

See **[all types](/src/Type)**

### Extra functionality

[](#extra-functionality)

Materialized path level calculation example:

```
use Vhood\TreeType\Converter;
use Vhood\TreeType\Type\MaterializedPath;

$materializedPath = [
    [
        'name' => 'node1',
        'path' => '/1/',
    ],
    [
        'name' => 'node2',
        'path' => '/1/2/',
    ],
];

$materializedPathConverter = new Converter(new MaterializedPath($materializedPath));

print_r($materializedPathConverter->toMaterializedPath('path', '/', 'level'));

// Array
// (
//     [0] => Array
//         (
//             [name] => node1
//             [path] => /1/
//             [level] => 1
//         )

//     [1] => Array
//         (
//             [name] => node2
//             [path] => /1/2/
//             [level] => 2
//         )

// )
```

Other features:

- nodes identification
- keys renaming
- keys removing

See the **[converting interface](/src/Contract/TypeConverter.php)**

---

[History](/CHANGELOG.md)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 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 ~23 days

Recently: every ~57 days

Total

13

Last Release

1226d ago

Major Versions

0.9.1 → 1.0.02022-07-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/f1f439b4337e659c715b5c5ad4673a35b4787c550fcafd9b1d6011a9aed661a5?d=identicon)[vhood](/maintainers/vhood)

---

Top Contributors

[![vhood](https://avatars.githubusercontent.com/u/55533574?v=4)](https://github.com/vhood "vhood (61 commits)")

---

Tags

ajacency-listmaterialized-pathmaterialized-pathsnested-setnested-setstreetree-structuretreemaptreesarraytreeadjacency listnested-setmaterialized path

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vhood-tree-converter/health.svg)

```
[![Health](https://phpackages.com/badges/vhood-tree-converter/health.svg)](https://phpackages.com/packages/vhood-tree-converter)
```

###  Alternatives

[doctrine/collections

PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.

6.0k411.1M1.2k](/packages/doctrine-collections)[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k295.3M2.5k](/packages/symfony-property-access)[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k9.2M108](/packages/cuyz-valinor)[knplabs/knp-menu

An object oriented menu library

1.4k55.8M285](/packages/knplabs-knp-menu)[league/config

Define configuration arrays with strict schemas and access values with dot notation

564302.2M24](/packages/league-config)

PHPackages © 2026

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