search
Homephp教程php手册php获取分类下的所有子类方法

php获取分类下的所有子类方法

Jun 06, 2016 pm 07:52 PM
linuxphpClassificationmethodObtainEnter

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 获取分类下面的所有子类方法: static function getMenuTree($arrCat, $parent_id = 0, $level = 0,$all=True) { static $arrTree; //使用static代替global if(!$all) $arrTree =''; if( empty

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  获取分类下面的所有子类方法:

  static function getMenuTree($arrCat, $parent_id = 0, $level = 0,$all=True)

  {

  static  $arrTree; //使用static代替global

  if(!$all) $arrTree ='';

  if( empty($arrCat)) return FALSE;

  $level++;

  if($level == 1) $arrTree[] = $parent_id;

  foreach($arrCat as $key => $value)

  {

  if($value['parent_cid' ] == $parent_id)

  {

  //$value[ 'level'] = $level;

  $arrTree[] = $value['cid'];

  unset($arrCat[$key]); //注销当前节点数据,减少已无用的遍历

  self::getMenuTree($arrCat, $value[ 'cid'], $level);

  }

  }

  return $arrTree;

  }

  用上面这个方法的前提是要把分类写到缓存文件中,缓存文件写入方法如下:

  public function actionIndex2()

  {

  $filepath = Yii::getPathOfAlias('application')。'/data/';

  $arr = array();

  $db = Yii::app()->db;

  $listinfo = $db->createCommand("select name,cid,parent_cid,root_cid from item_cat_info")->queryAll();

  foreach($listinfo as $val)

  {

  $arr[$val['cid']] = array('cid'=>$val['cid'],'name'=>$val['name'],'parent_cid'=>$val['parent_cid'],'root_cid'=>$val['root_cid']);

  }

  $applist = "";

  file_put_contents($filepath.'itemcat.php', $applist);

  }

php获取分类下的所有子类方法

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.