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

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

hxari/tree
==========

Create a Tree structure using an Array.

v1.0.3(3y ago)16GPL-3.0PHPPHP ^8.0

Since Mar 2Pushed 3y ago1 watchersCompare

[ Source](https://github.com/hxAri/Tree)[ Packagist](https://packagist.org/packages/hxari/tree)[ RSS](/packages/hxari-tree/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)DependenciesVersions (4)Used By (0)

[![Tree Avatar](https://raw.githubusercontent.com/hxAri/hxAri/main/public/images/1653507345%3B50XUUPql.z.png)](https://raw.githubusercontent.com/hxAri/hxAri/main/public/images/1653507345%3B50XUUPql.z.png)

Abouts
------

[](#abouts)

Create a Tree structure using an Array or Object. You want to create a tree structure like in the Command Line Interface? Sans!... *Tree* is the solution!.. It's really very simple and without the hassle!

In addition to using PHP, Tree has also been made for the JavaScript version, but now it only supports HTML display, for the next version maybe I will add a feature so that the JavaScript version of Tree can run on the Command Line Interface along with NodeJS.

Install
-------

[](#install)

Install with Composer

```
composer require hxari/tree

```

Install with Wget

```
wget https://raw.githubusercontent.com/hxAri/Tree/main/src/PHPTree/Tree.php

```

Install with Git

```
git clone https://github.com/hxAri/Tree

```

Or you can also download it directly from [Github](https://github.com/hxAri/Tree/archive/refs/heads/main.zip) if you don't want to bother.

Usage
-----

[](#usage)

Very simple usage.

```
use Tree\Tree;

// If you use Composer.
require "vendor/autoload.php";

// If you use Git/ Download.
require "Tree/Tree.php";

// If you use Wget.
require "Tree.php";

// Suppose you have an array.
$array = [
    'users' => [
        [
            'id' => 2288,
            'profile' => [
                'fname' => "Xyz",
                'uname' => "xyz"
            ]
        ],
        [
            'id' => 2289,
            'profile' => [
                'fname' => "Xxx",
                'uname' => "xxx"
            ]
        ]
    ],
    'malware' => [
        'trojan' => "Horse"
    ]
];

// Creating a tree structure.
echo Tree::create( $array );
```

This will display.

```
├── users
│   ├── Array
│   │   ├── id
│   │   │   └── 2288
│   │   └── profile
│   │       ├── fname
│   │       │   └── Xyz
│   │       └── uname
│   │           └── xyz
│   └── Array
│       ├── id
│       │   └── 2289
│       └── profile
│           ├── fname
│           │   └── Xxx
│           └── uname
│               └── xxx
└── malware
    └── trojan
        └── Horse

```

Methods
-------

[](#methods)

Explanation for method.

The `::create` method has three parameters which are:

```
Tree::create( Array $data, Int $start = 0, Int $flags = 0 )
```

Parameter `$data` is an array data that will be used to create a tree structure.

The `$start` parameter is used to identify how many spaces will be used for the start.

Meanwhile, the `$flags` parameter is used to identify whether to use a line or a dot to create the structure.

The `::setKeyHandler` method has one parameter with `Callable` type. This is quite useful when you want to color the key values ​​of your array elements.

```
// Method.
Tree::setKeyHandler( Callable $handler );

// Method Use.
Tree::setKeyHandler( fn( Mixed $key ) => "\e[1;32m{$key}" );

// Or
Tree::setKeyHandler( function( Mixed $key ) {
    // Something....
});
```

For `::setValHandler` method also has the same function.

Constants
---------

[](#constants)

**Class****Constants****Type****Value**Tree\\TreeSPACEpublicStringTree\\TreeNONEpublicStringTree\\TreeSTRAIGHT\_LINEpublicStringTree\\TreeMIDDLE\_LINEpublicStringTree\\TreeLAST\_LINEpublicStringTree\\TreeLINEpublicIntTree\\TreeDOUBLE\_POINTpublicStringTree\\TreePOINTpublicIntLicense
-------

[](#license)

All source code under [GNU General Public License](https://github.com/hxAri/Tree/blob/main/LICENSE)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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

Total

3

Last Release

1307d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/31ee16ff3b80c0a79297bf5d6e83d6cea7e953501dcdaaead1300c49327cc180?d=identicon)[hxAri](/maintainers/hxAri)

---

Top Contributors

[![hxAri](https://avatars.githubusercontent.com/u/90847846?v=4)](https://github.com/hxAri "hxAri (26 commits)")

---

Tags

faibaphptreephptree

### Embed Badge

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

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

###  Alternatives

[loophp/phptree

An implementation of tree data structure

981.8M2](/packages/loophp-phptree)[efureev/laravel-trees

Multi-Tree structures for Laravel

14253.3k4](/packages/efureev-laravel-trees)[chdemko/sorted-collections

Sorted Collections for PHP &gt;= 8.2

222.5M3](/packages/chdemko-sorted-collections)

PHPackages © 2026

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