无限级分类的写法

public function catetree(){
        $cateres = $this->select();
        return $this->sort($cateres);
    }
    
    public function sort($data,$pid=0,$level=0){
        static $arr = array();
        foreach($data as  $k => $v){
            if($v['pid'] == $pid){ //pid=0 顶级栏目
                $v['level']=$level;
                $arr[]= $v;
                $this->sort($data,$v['id'],$v['level']+1); //递归
            }
        }
        return $arr;
    }

显示分隔符的添加

<td align="left">
{if condition="$cate['level'] neq 0"}|{/if}
<?php echo str_repeat('-',$cate['level']*5)?>
{$cate.catename}<!--str_repeat('-',$cate['level'])循环显示分隔符-->
</td
原文地址:https://www.cnblogs.com/my2018/p/8974650.html