ThinkPHP implements recursive loop columns and outputs infinite pole based on the tree structure. thinkphp recursion. ThinkPHP implements recursive loop columns and outputs Infinitus according to the tree structure, thinkphp recursion This article provides an example of thinkPHP to implement recursive loops and output thinkPHP to implement recursive loops based on the infinite pole in the tree structure. thinkphp recursion
The example in this article describes how thinkPHP implements recursive loops and outputs Infinitus based on the tree structure. We will share this with you for your reference. The details are as follows:
The thinkphp recursive loop column is used to output an infinite number of outputs according to the tree structure and save it as an array, which facilitates template calling.
The code is as follows:
Private function categoryTree ($ parentid, $ level) // This is a private function {$ Category = D ('Category ') because it is used in this class '); $ result = $ Category-> where ("'parentid' = ". $ parentid)-> order ("listorder desc, catid desc")-> select (); if ($ result) {$ count = count ($ result ); // The current number of subtopics $ level ++; // subtopic level foreach ($ result as $ v) {$ index ++; if ($ count = $ index) $ step = "your-"; else $ step = "your-"; $ 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 a subtopic {$ newData = $ newData + $ this-> categoryTree ($ v ['catid'], $ level) ;}}return $ newData ;}
Save the php recursive column as an array
PS: the code in this article is not formatting and beautifying. we recommend several formatting and beautifying tools on this site. I believe you can use these tools in future development:
Php code online formatting and beautification tools:
Http://tools.jb51.net/code/phpformat
JavaScript code beautification/compression/Formatting/encryption tools:
Http://tools.jb51.net/code/jscompress
Online XML formatting/compression tools:
Http://tools.jb51.net/code/xmlformat
SQL code online formatting and beautification tools:
Http://tools.jb51.net/code/sqlcodeformat