Thinkphp implements recursive loop column and follows the method of infinite pole output of tree structure, thinkphp recursion
In this paper, we describe the method of thinkphp to implement recursive cyclic columns and to output infinite poles according to tree structure. Share to everyone for your reference, as follows:
This uses the thinkphp recursive loop column to output the infinite pole of the tree structure and save it as an array, which facilitates the template invocation
The specific code is as follows:
Private Function CategoryTree ($parentid, $level)//Because it is used in this class, it is set to private functions {$Category = D (' Category '); $result = $Category- >where ("' ParentID ' =". $parentid)->order ("Listorder desc,catid desc")->select (); if ($result) {$count =count ( $result)///Current sub-column number $level++;//sub-column 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 ']. "
if ($v [' Child ']==1)//If there are sub-columns {$newData = $newData + $this->categorytree ($v [' catid '], $level);}}} return $newData;}
PHP recursive column saved as an array
PS: This code is not formatted to beautify the processing, here are recommended several of the format of the site landscaping tools, I believe that you can use in the development of the future:
PHP Code online format Beautification tool:
Http://tools.jb51.net/code/phpformat
JavaScript code beautification/compression/formatting/encryption Tools:
Http://tools.jb51.net/code/jscompress
Online XML format/compression tool:
Http://tools.jb51.net/code/xmlformat
SQL code online Format beautification tool:
Http://tools.jb51.net/code/sqlcodeformat
More interested in thinkphp related content readers can view this site topic: "thinkphp Introductory Tutorial", "thinkphp Common Methods Summary", "Smarty Template Primer Basic Tutorial" and "PHP template technology Summary."
It is hoped that this article is helpful to the PHP program design based on thinkphp framework.
http://www.bkjia.com/PHPjc/1127841.html www.bkjia.com true http://www.bkjia.com/PHPjc/1127841.html techarticle thinkphp implement recursive loop column and according to the method of the infinite pole output of tree structure, thinkphp recursion This example tells the thinkphp to realize recursive loop column and follow the tree structure infinite pole output ...