导航条上三层数据

 1 /*导航条上三层数据*/
 2 public function NavData()
 3 {
 4     //取出所有数据
 5     $data=$this->select();
 6     $_ret=array();
 7     foreach ($data as $k => $v) {
 8         if ($v['parent_id']==0) {
 9             //取出二级分类
10             foreach ($data as $k1 => $v1) {
11                 if ($v1['parent_id']==$v['id']) {
12                     //取出三级分类
13                     foreach ($data as $k2 => $v2) {
14                         
15                         if ($v2['parent_id']==$v['id']) {
16                             $v1['children'][]=$v2;//标记二级分类下的三级分类
17                         }
18                     }
19                     $v['children'][]=$v1;//标记一级分类下的二级分类
20                 }
21             }
22             $_ret[]=$v;
23         }
24     }
25     return $_ret;
26 }

 

posted @ 2017-07-25 12:48  adstat  阅读(128)  评论(0编辑  收藏  举报