ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` /** * 获取分类函数 */ function getTree($list,$type='1',$pid=0,$level=0){ $return = []; if($type=='1'){ foreach ($list as $k => $v) { if($v['pid']==$pid){ $return[$k] = $v; $return[$k]['title'] = str_repeat(' ├ ',$level).$v['title']; $return[$k]['child'] = getTree($list,'1',$v['id'],$level+1); } unset($list[$k]); } }else{ foreach ($list as $k => $v) { if($v['pid']==$pid){ $return[$v['id']] = $v; $return[$v['id']]['title'] = str_repeat('├ ',$level).$v['title']; $return = $return+ getTree($list,'2',$v['id'],$level+1); } unset($list[$k]); } } return $return; } ```