zoukankan      html  css  js  c++  java
  • PHP 递归读取无限级分类

     1 /**
     2      * 【获取第一级分类】
     3      *  20170829
     4      *
     5      * @return array
     6      */
     7     public function getCateList(){
     8         $this->catelog = [];
     9         //获取第一级分类
    10         $rst = $this->find()->where(['is_root'=>0, 'status' => 10])->asArray()->all();
    11 
    12         if($rst){
    13             foreach ($rst as $row){
    14                 $this->catelog[] = [
    15                     'id' => $row['id_cate'],
    16                     'catename' => $row['catename'],
    17                     'catename_en' => $row['catename_en'],
    18                     'cover' => $row['cover'],
    19                     'depath' => 0,
    20                     'is_root' => $row['is_root'],
    21                 ];
    22                 //获取子分类
    23                 $this->getChild($row['id_cate'], 1);
    24 
    25             }
    26         }
    27 
    28         return $this->catelog;
    29     }
    30 
    31 
    32     /**
    33      * 【递归获取所有子分类】
    34      *  20170829
    35      *
    36      * @param $id
    37      * @param $depth
    38      */
    39     function getChild($id,$depth ){
    40         //global $catalog;
    41 
    42         $rst = $this->find()->where(['is_root' => $id, 'status' => 10])->asArray()->all();
    43         if (count($rst) > 0) {
    44             foreach ($rst as $row){
    45                 $this->catelog[] = [
    46                     'id' => $row['id_cate'],
    47                     'catename' => $row['catename'],
    48                     'catename_en' => $row['catename_en'],
    49                     'cover' => $row['cover'],
    50                     'depath' => $depth,
    51                     'is_root' => $row['is_root'],
    52                 ];
    53                 $this->getChild($row['id_cate'], 2);
    54             }
    55         }
    56 
    57     }
  • 相关阅读:
    (四)安装硬件驱动程序
    (三)操作系统安装与更新
    (二)主板BIOS设置与硬盘分区、调整
    通过ip远程控制电脑
    (一)计算机基本组成部分
    计算机与操作系统
    单位换算
    TestDirector(TD)—测试管理工具
    QualityCenter(QC)—测试管理工具
    teamviewer破解版
  • 原文地址:https://www.cnblogs.com/reader/p/7521369.html
Copyright © 2011-2022 走看看