private function getTreeItems($items)
{
$tree = [];
foreach ($items as $item){
if (isset($items[$item['pid']])){
$items[$item['pid']]['children'][] = &$items[$item['mid']];
}else{
$tree[] = &$items[$item['mid']];
}
}
return $tree;
}
private function getTree($items,$pid=0)
{
$tree = [];
foreach ($items as $item){
if ($item['pid'] == $pid){
$tree[$item['mid']] = $item;
$tree[$item['mid']]['children'] = $this->getTree($items,$item['mid']);
}
}
return $tree;
}
private function formatTree($items,&$res=[])
{
foreach ($items as $key => $item){
if (isset($item['children'])){
$tem = $item['children'];
unset($item['children']);
$res[] = $item;
$this->formatTree($tem,$res);
}else{
$res[] = $item;
}
}
return $res;
}
再进行第二级遍历进,一定要判断是否有二级菜单,如果没有判断,会报错
<div class="menu_dropdown bk_2">
@foreach($menus as $menu)
<dl id="menu-article">
<dt><i class="Hui-iconfont"></i> {{$menu['title']}}<i class="Hui-iconfont menu_dropdown-arrow"></i></dt>
@if(isset($menu['children']) && $menu['children'])
<dd>
@foreach($menu['children'] as $m)
<ul>
<li><a href="javascript:;" controller = "{{$m['controller']}}" action = "{{$m['action']}}" onclick="menu_fire(this)"
"title="资讯管理">{{$m['title']}}</a>
</li>
</ul>
@endforeach
</dd>
@endif
</dl>
@endforeach
</div>