Php unlimited classification implementation method analysis, php unlimited Classification

Source: Internet
Author: User

Php unlimited classification implementation method analysis, php unlimited Classification

This example describes how to implement php unlimited classification. We will share this with you for your reference. The details are as follows:

1. Recursion

Public function getInfo () {$ data = $ this-> select (); $ arr = $ this-> noLimit ($ data, $ f_id = 0, $ level = 0 ); return $ arr;} // infinitus classification 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. Normal

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;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.