樹状無制限極分類getTree tree

770 ワード

            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;
}