This article mainly introduces the method of thinkPHP to implement recursive loop columns and output infinite pole according to the tree structure, involving thinkPHP database query, array traversal and string operation and other skills. Friends who need it can refer to it
The example of this article describes the method of thinkPHP to implement recursive loop columns and output infinitely according to the tree structure. Share it with everyone for your reference, the details are as follows:
Here we use thinkphp recursive loop column to output infinitely according to the tree structure, and save it as an array, which is convenient for template calling
The specific code is as follows:
private function categoryTree($parentid,$level) //因为是本类中使用所以定于为私有函数 { $Category= D('Category'); $result = $Category->where("`parentid`=".$parentid)->order("listorder desc,catid desc")->select(); if($result) { $count=count($result);//当前子栏目个数 $level++;//子栏目层级 foreach($result as $v) { $index++; if($count==$index) $step="└─"; else $step="├─"; $step.=str_repeat(' ',$level-1); $nbsp=str_repeat(' ',$level-1); $nstr=$nbsp.$step; if($parentid==0) $nstr=''; $v['step']=$nstr; $newData[$v['catid']]=$v; //echo $nstr.$v['catname']."<br />"; if($v['child']==1)//如果有子栏目 { $newData=$newData+$this->categoryTree($v['catid'],$level); } } } return $newData; }
php recursive columns are saved as arrays
Related recommendations:
thinkPHP implements multi-field fuzzy matching query Method
thinkphp implements file upload and file download
The above is the detailed content of thinkPHP implements a method of recursively looping columns and outputting infinitely according to the tree structure. For more information, please follow other related articles on the PHP Chinese website!