分类:PHP 发布时间:2018-07-04 14:59:00
表结构 title,cid,parentid,... ... ``` /* * category 分类数组 * cid 栏目ID * step 分类层级 * parentid 父级ID * title 栏目名称 */ public function tree($category,$cid,$step) { static $tree=[]; foreach($category as $val) { if($val['parentid'] == $cid) { $flg = str_repeat(' ├─ ',$step); $val['title'] = $flg.$val['title']; $tree[] = $val; Category::tree($category , $val['cid'] ,$step+1); } } return $tree; } ``` 简单使用 ``` $result = tree($category,0,0); ```
搜索
文章分类
最新文章