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

yipeiwu_com6年前PHP代码库

本文实例讲述了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字符串(string)用法总结》、《PHP数组(Array)操作技巧大全》、《PHP基本语法入门教程》、《PHP运算与运算符用法总结》、《php面向对象程序设计入门教程》、《PHP网络编程技巧总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总

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

相关文章

PHP标准库(PHP SPL)详解

PHP标准库(PHP SPL)详解

什么是SPL? SPL,PHP 标准库(Standard PHP Library) ,此从 PHP 5.0 起内置的组件和接口,并且从 PHP5.3 已逐渐的成熟。SPL 其实在所有的...

PHP 常用时间函数资料整理

php常用的时间函数 测试环境:php5.3.29 unix时间戳(从Unix 纪元(January 1 1970 00:00:00 GMT)到给定时间的秒数。)。以下简称时间戳。 返回...

php daddslashes()和 saddslashes()有哪些区别分析

//GPC过滤,自动转义$_GET,$_POST,$_COOKIE中的特殊字符,防止SQL注入攻击 $_GET = saddslashes($_GET); $_POST = saddsl...

centos 5.6 升级php到5.3的方法

centos 5.6 升级php到5.3的方法

升级很容易,先卸载 php 5.1.6 yum remove php* 然后安装 yum install php53* 就可以了...

使用PHPWord生成word文档的方法详解

本文实例讲述了使用PHPWord生成word文档的方法。分享给大家供大家参考,具体如下: 有时我们需要把网页内容保存为Word文档格式,以供其他人员查看和编辑。PHPWord是一个用纯P...