无限极分类--递归法
作者:互联网
/** * 无限极分类 * @param array $data 可迭代数组 * @param int $pid 父级id * @return array */ public static function getTree(array $data,$pid = 0): array { $tree = []; foreach ($data as &$item){ if ($item['pid'] === $pid){ $item['children'] = self::getTree($data,$item['id']); $tree[] = $item; } } return $tree; }
标签:递归,--,tree,pid,param,item,无限极,array,data 来源: https://www.cnblogs.com/coder-yang/p/16597941.html