How to write infinite classification

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); // recursive 
            }
        }
        return $arr;
    }

Addition of Display Separator

<td align="left">
{if condition="$cate['level'] neq 0"}|{/if}
<?php echo str_repeat('-',$cate['level']*5)?>
{$cate.catename}<!--str_repeat('-',$cate['level'])循环显示分隔符-->
</td

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325169198&siteId=291194637