https://github.com/wxxiong6/tree
使用递归把有规则数据,处理成树形数据结构。适用场景菜单、权限、分类等功能。
https://github.com/wxxiong6/tree
tree tree-data
Last synced: 2 months ago
JSON representation
使用递归把有规则数据,处理成树形数据结构。适用场景菜单、权限、分类等功能。
- Host: GitHub
- URL: https://github.com/wxxiong6/tree
- Owner: wxxiong6
- License: mit
- Created: 2016-09-22T08:03:32.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-07-08T02:01:22.000Z (over 5 years ago)
- Last Synced: 2025-09-06T15:54:23.266Z (7 months ago)
- Topics: tree, tree-data
- Language: PHP
- Homepage:
- Size: 37.1 KB
- Stars: 6
- Watchers: 0
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/wxxiong6/tree)
[](https://github.com/wxxiong6/tree/network)
[](https://packagist.org/packages/wxxiong6/tree)

## tree
- 使用递归把数据构造成树形结构数据
- 常用于菜单、权限、分类等功能实现
- 避免多次查询数据库,使用php来处理
## Installation
```shell
composer require wxxiong6/tree
```
## Usage
```PHP
//设置主键、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
)
)
)
)
)
)
```