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

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

wxxiong6/tree
=============

tree data 使用递归生成树形数据，简单实用

v1.2.1(5y ago)63503MITPHPPHP &gt;=7.0CI failing

Since Jun 3Pushed 5y agoCompare

[ Source](https://github.com/wxxiong6/tree)[ Packagist](https://packagist.org/packages/wxxiong6/tree)[ RSS](/packages/wxxiong6-tree/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (3)Dependencies (1)Versions (5)Used By (0)

[![Build Status](https://camo.githubusercontent.com/0a687c329824343ce0d3134a01f924aa5c4b1c102a36618b2410fc07ade993bb/68747470733a2f2f7472617669732d63692e6f72672f777878696f6e67362f747265652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/wxxiong6/tree)[![GitHub forks](https://camo.githubusercontent.com/83812b4661566e63ad9b62fa937322dee0d558f11c75cbf1be852a8525d758ae/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f777878696f6e67362f747265652e737667)](https://github.com/wxxiong6/tree/network)[![Packagist](https://camo.githubusercontent.com/7490937012a599a6fd4e65c1d6869ca6959e5e9be9fe9e8e33e41eb223cba4f1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f777878696f6e67362f747265652e737667)](https://packagist.org/packages/wxxiong6/tree)[![Packagist](https://camo.githubusercontent.com/83237784257ed56c291d97519764c722aedd186293e844a7f2a39ac3af330ff4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f777878696f6e67362f74726565)](https://camo.githubusercontent.com/83237784257ed56c291d97519764c722aedd186293e844a7f2a39ac3af330ff4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f777878696f6e67362f74726565)

tree
----

[](#tree)

- 使用递归把数据构造成树形结构数据
- 常用于菜单、权限、分类等功能实现
- 避免多次查询数据库,使用php来处理

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

[](#installation)

```
composer require wxxiong6/tree
```

Usage
-----

[](#usage)

```
//设置主键、parent标识名称 子节点名称
Tree::setConfig($primary = '', $parentId = '', $child = '');
//生成tree
Tree::makeTree($data);
```

运行结果

```
Array
(
    [0] = Array
   (
      [id] = 1
       [city] = 中国
       [parent_id] = 0
        [child] = Array
         (
                 [0] = Array
                      (
                             [id] = 2
                            [city] = 北京
                             [parent_id] = 1
                             [child] = Array
                                (
                                 [0] = Array
                                         (
                                             [id] = 3
                                            [city] = 北京市
                                            [parent_id] = 2
                                            [child] = Array
                                                (
                                                   [0] = Array
                                                       (
                                                            [id] = 4
                                                            [city] = 东城区
                                                            [parent_id] = 3
                                                        )

                                                )

                                        )

                                )

                        )

                    [1] = Array
                        (
                            [id] = 11
                            [city] = 上海
                            [parent_id] = 1
                            [child] = Array
                                (
                                    [0] = Array
                                        (
                                            [id] = 12
                                            [city] = 上海市
                                            [parent_id] = 11
                                        )

                                )

                        )

                )

        )

)

```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

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

Total

4

Last Release

2136d ago

PHP version history (2 changes)v1.0PHP &gt;=5.4

v1.2.1PHP &gt;=7.0

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

treetree-datatreetree-data

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[knplabs/knp-menu

An object oriented menu library

1.4k55.8M287](/packages/knplabs-knp-menu)[cuyz/valinor

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

1.5k9.2M108](/packages/cuyz-valinor)[bluem/tree

Library for handling tree structures based on parent IDs

252916.1k7](/packages/bluem-tree)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

320392.1k17](/packages/codewithdennis-filament-select-tree)[loophp/phptree

An implementation of tree data structure

981.8M2](/packages/loophp-phptree)[kartik-v/yii2-tree-manager

An enhanced tree management module with tree node selection and manipulation using nested sets.

156529.0k15](/packages/kartik-v-yii2-tree-manager)

PHPackages © 2026

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