<?php
/**
* 递归查询子分类
* @param int $parent_id 父类ID
* @return array
*/
public function getAllCategory($parent_id = 0) {
$menus = $this->where('parent_id' , $parent_id)->orderBy('order' ,'asc')->get();
$all_menus = array();
if (!empty($menus)) {
foreach ($menus as $key => $menu) {
$all_menus[$menu->id] = $menu;
//查询子菜单
$menu_child = $this->getAllMenu($menu->id);
if (!empty($menu_child)) {
//子菜单不为空放在 child 数组中
$all_menus[$menu->id]->child = $menu_child;
}
}
}
return $all_menus;
}
public static function getTree(&$data, $pid = 0) { $tree = array(); if(empty($data)){ return null; } foreach ($data as $v) { if ($v['pid'] == $pid) { $v['_child'] = self::getTree($data, $v['id']); $tree[] = $v; } } return $tree; }
最后
以上就是唠叨芹菜最近收集整理的关于递归查询子分类的全部内容,更多相关递归查询子分类内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复