ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## **1.递归查询** ~~~ static public function infinityCategory($data,$fid=0) { $ruleArr = []; foreach ($data as $k => $v) { if ($v['fid'] == $fid) { $v['lower'] = self::infinityCategory($data,$v['id']); $ruleArr[] = $v; unset($data[$k]); } } return $ruleArr; } ~~~ ## **2.查询所有分类并在子分类加|----** ~~~ static public function getCates(){ //获取数据并排序 $cates_data = Db::query("select *,concat(path,',',id) as paths from shop_cates order by paths"); foreach ($cates_data as $key => $value) { //统计$value->path中 ,出现的次数 $n = substr_count($value['path'],','); //重复使用一个字符串 $cates_data[$key]['name'] = "".str_repeat('|----',$n).$value['name']; } return $cates_data; } ~~~