/**
* 无线分类
* @param array $items
* @return array
*/
public function getTree($arr,$parent_id){
$tree = [];
foreach ($arr as $k=>$v){
if ($v['pid'] == $parent_id){
$v['child'] = $this->getTree($arr,$v['id']);
if ($v['child'] == null){
unset($v['child']);
}
$tree[] = $v;
}
}
return $tree;
}
方法二:
/**
* 栏目树-函数方法整理-级别
* @param $tree
* @param $categories
* @param $parentId
* @return array
*/
protected function makeCategoryTree(&$tree, &$categories, $parentId)
{
static $depth = 0;
if (isset($categories[$parentId]) && is_array($categories[$parentId])) {
foreach ($categories[$parentId] as $category) {
++$depth;
$category['depth'] = $depth;
$tree[] = $category;
$this->makeCategoryTree($tree, $categories, $category['id']);
--$depth;
}
}
return $tree;
}