一款超级好用的无限级分类

来源:互联网 发布:免费网络视频会议系统 编辑:程序博客网 时间:2024/04/30 04:30

数据库栏目字段               id       name    fid            state    

/**
* list 是栏目数组集
* fcid 是栏目的父级栏目
* $html 是为了区分本级栏目与上级栏目的区别
* */
function tree(&$list,$fcid=0,$level=0,$html='--'){
   static $tree = array();
   foreach($list as $v){
       if($v['fcid'] == $fcid){
           $v['sort'] = $level;
           $v['html'] = str_repeat($html,$level);
           $tree[] = $v;
           tree($list,$v['id'],$level+1);
       }
   }
   return $tree;
}


1 0