公共库

This commit is contained in:
wuyanwen
2019-12-12 09:14:08 +08:00
parent d154f3e1ac
commit ca4272d7a6
8 changed files with 229 additions and 54 deletions

View File

@@ -1 +1,22 @@
<?php
namespace catcher;
class Tree
{
public static function done(array $items, $pid = 0, $pidField = 'parent_id', $children = 'children')
{
$tree = [];
foreach ($items as $key => $item) {
if ($item[$pidField] == $pid) {
$child = self::done($items, $item['id'], $pidField);
$item[$children] = count($child) ? $child : [];
$tree[] = $item;
}
}
return $tree;
}
}