PHPackages                             muhammetsafak/data-tree - 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. muhammetsafak/data-tree

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

muhammetsafak/data-tree
=======================

Converts a one-dimensional array into a tree with relationships as a multidimensional array.

0.1(3y ago)05MITPHPPHP &gt;=7.4

Since Jan 14Pushed 3y ago1 watchersCompare

[ Source](https://github.com/muhammetsafak/DataTree)[ Packagist](https://packagist.org/packages/muhammetsafak/data-tree)[ RSS](/packages/muhammetsafak-data-tree/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

DataTree
========

[](#datatree)

This simple library/class allows you to get a tree structure using a one-dimensional array.

**Note :** It took approximately 1.10 seconds for this library to process an array with 1,000,000 elements, using over 400MB of memory. Keep in mind that the larger the data you are processing, the more memory and time you will need.

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

[](#installation)

```
composer require muhammetsafak/data-tree

```

Usage
-----

[](#usage)

```
require_once "vendor/autoload.php";
use MuhammetSafak\DataTree\TreeGenerator;

$data = [
    ['ID' => 1, 'parent_id' => 0, 'random_name' => 'Random #1'],
    ['ID' => 2, 'parent_id' => 0, 'random_name' => 'Random #2'],
    ['ID' => 3, 'parent_id' => 1, 'random_name' => 'Random #3'],
    ['ID' => 4, 'parent_id' => 2, 'random_name' => 'Random #4'],
    ['ID' => 5, 'parent_id' => 0, 'random_name' => 'Random #5'],
    ['ID' => 6, 'parent_id' => 2, 'random_name' => 'Random #6'],
];

$tree = (new TreeGenerator($data))
    ->setRelation('id', 'parentId')
    ->setReName('ID', 'id')
    ->setReName('parent_id', 'parentId')
    ->setReName('random_name', 'name')
    ->setChildNodeName('@childrens')
    ->toTree();

print_r($tree);
```

Output :

```
Array
(
    [0] => Array
        (
            [id] => 1
            [parentId] => 0
            [name] => Random #1
            [@childrens] => Array
                (
                    [0] => Array
                        (
                            [id] => 3
                            [parentId] => 1
                            [name] => Random #3
                        )

                )

        )

    [1] => Array
        (
            [id] => 2
            [parentId] => 0
            [name] => Random #2
            [@childrens] => Array
                (
                    [0] => Array
                        (
                            [id] => 4
                            [parentId] => 2
                            [name] => Random #4
                        )

                    [1] => Array
                        (
                            [id] => 6
                            [parentId] => 2
                            [name] => Random #6
                        )

                )

        )

    [2] => Array
        (
            [id] => 5
            [parentId] => 0
            [name] => Random #5
        )

)

```

Credits
-------

[](#credits)

- [Muhammet ŞAFAK](https://www.muhammetsafak.com.tr) &lt;&gt;

License
-------

[](#license)

Copyright © 2022 [MIT License](./LICENSE)

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

1218d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b6b34f3ac8938d8ee52ba3bd260680855dc5715c7b2929d9380de30d15a67dd?d=identicon)[muhammetsafak](/maintainers/muhammetsafak)

---

Top Contributors

[![muhammetsafak](https://avatars.githubusercontent.com/u/104234499?v=4)](https://github.com/muhammetsafak "muhammetsafak (2 commits)")

### Embed Badge

![Health badge](/badges/muhammetsafak-data-tree/health.svg)

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

###  Alternatives

[zerodahero/laravel-workflow

Integerate Symfony Workflow component into Laravel.

204815.2k4](/packages/zerodahero-laravel-workflow)

PHPackages © 2026

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