树状无限极分类

树状无限极分类 提供2种方式

function getTree($list,$id=0,$level=0) {

           static $tree = array();

          foreach($list as $row) {

              if($row['pid']==$id) {

                $row['level'] = $level;

                $row['name'] = str_repeat('----',$level). $row['name'];

                $tree[] = $row;

                $this->getTree($list, $row['id'], $level + 1);

            }

        }

    return $tree;

}



function getTree($list,$pid=0,$level=0) {

static $tree = array();

foreach($list as $row) {

if($row['dept_pid']==$pid) {

$row['dept_level'] = $level;

$tree[] = $row;

getTree($list, $row['dept_id'], $level + 1);

}

}

return $tree;

}

你可能感兴趣的:(树状无限极分类)