首页 > 语言 > PHP > 正文

php无限级分类实现方法分析

2024-05-04 23:51:20
字体:
来源:转载
供稿:网友

本文实例讲述了php无限级分类实现方法。分享给大家供大家参考,具体如下:

1. 递归

public function getInfo(){$data=$this->select();$arr=$this->noLimit($data,$f_id=0,$level=0);return $arr;}//无限极分类public function noLimit($data,$f_id=0,$level=0){static $lists=array();foreach($data as $key=>$v){  if($v['f_id']==$f_id){    $v['level']=$level;    $lists[]=$v;    $this->noLimit($data,$v['q_id'],$level+1);  }}return $lists;}

2. 普通

public function getInfo(){$u_id=session('u_id');$data=$this->join("user join user_role on user.u_id=user_role.u_id join role_quan on user_role.j_id=role_quan.j_id join quan on quan.q_id=role_quan.q_id")-> where("user.u_id=$u_id and quan.f_id=0")->group("quan.q_id")->select(); foreach($data as $k=>$v){ $arr=$this->join("user join user_role on user.u_id=user_role.u_id join role_quan on user_role.j_id=role_quan.j_id join quan on quan.q_id=role_quan.q_id")-> where("user.u_id=$u_id and quan.f_id=".$v['q_id'])->group("quan.q_id")->select(); $data[$k]['son']=$arr;}

希望本文所述对大家PHP程序设计有所帮助。


注:相关教程知识阅读请移步到PHP教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选