waughj/flat-to-hierarchy-sorter
Composer 安装命令:
composer require waughj/flat-to-hierarchy-sorter
包简介
Sorts flat list of nodes into hierarchy.
README 文档
README
Sorts flat list of nodes with IDs and parent IDs into layered list of nodes with IDs and lists of children to make iteration easier.
Example
use WaughJ\FlatToHierarchySorter\FlatToHierarchySorter;
use WaughJ\FlatToHierarchySorter\HierarchicalNode;
$old_list =
[
new HierarchicalNode( 1, 0 ),
new HierarchicalNode( 2, 1 ),
new HierarchicalNode( 3, 1 ),
new HierarchicalNode( 4, 2 )
];
$sorted_list = FlatToHierarchySorter::sort( $old_list );
will return to equivalent of:
new HierarchicalNode
(
1,
0,
[
new HierarchicalNode( 2, 1, [ new HierarchicalNode( 4, 2 ) ] ),
new HierarchicalNode( 3, 1 )
]
);
Changelog
0.1.0
- Initial release
统计信息
- 总下载量: 69
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: AGPL-3.0-or-later
- 更新时间: 2019-10-18