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

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

tebru/tree
==========

A PHP tree data structure. Allows for referencing nodes by unique key.

v0.1.0(11y ago)2201MITPHPPHP &gt;=5.5.0

Since May 22Pushed 11y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

[![Build Status](https://camo.githubusercontent.com/0f5a069d094a719880544aa68d69797da25dd9e92a4e69540da1accd9cbcef4f/68747470733a2f2f7472617669732d63692e6f72672f74656272752f747265652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/tebru/tree)

Tree Data Structure
===================

[](#tree-data-structure)

This library aims to provide an object oriented way to create a tree data structure. Each node has a user defined unique id by which it is referenced.

Installing the project
----------------------

[](#installing-the-project)

Run `composer require tebru/tree:1.0.*`

Creating the tree
-----------------

[](#creating-the-tree)

Creating a tree is really easy. All you have to do is instantiate it: `$tree = new Tree();`This will create the tree object and create a root node to act upon.

### Create a node

[](#create-a-node)

There are many options for creating a node.

- Creating a node appended to the root node can be done like `$tree->createNode('node');`
- If you want to add this node to a different node you can do so like `$tree->createNode('node2', 'node');`
- You have the option to add arbitrary data to a node by doing `$tree->createNode('a_category', null, 'Foo Category');`
- Finally, you can specify the position your node should appear in the parent's children like `$tree->createNode('node', null, null, 10);`
    - You may not specify an position for an index that does not already exist
    - Setting the position will bump all existing nodes back 1 space starting with the node at the specified index

### Remove a node

[](#remove-a-node)

Just pass in the node id: `$tree->removeNode('node');`This will remove that node and all of its children from the tree.

### Move a node

[](#move-a-node)

This is also easy. Just specify the node id of the node you wish to move and the node id of its new parent: `$tree->moveNode('node', 'newNodeId');`

Testing
-------

[](#testing)

Run tests by running `phpunit` from the root directory.

Versioning
----------

[](#versioning)

This project uses semantic versioning \[\] for versioning.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

4379d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1831497?v=4)[Nate Brunette](/maintainers/natebrunette)[@natebrunette](https://github.com/natebrunette)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[cblink/laravel-excel-zip

627.3k](/packages/cblink-laravel-excel-zip)[asinfotrack/yii2-audittrail

Yii2-audittrail is a behavior and a set of widgets to track all modifications performed on a model

1727.0k](/packages/asinfotrack-yii2-audittrail)

PHPackages © 2026

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