Analysis of the implementation method of infinite level classification in PHP

黄舟
Release: 2023-03-06 07:44:01
Original
1810 people have browsed it

The example in this article describes the implementation method of unlimited classification in PHP. Share it with everyone for your reference, the details are as follows:
1. Recursive

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;
}
Copy after login

2. Ordinary

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;
}
Copy after login

The above is the content of the analysis of the PHP unlimited classification implementation method , for more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Related articles:

php recursively implements infinite classification trees

php uses recursive method to achieve infinite classification

Revealing the principle of infinite classification in php

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template