ThinkPHP implements recursive loop columns and outputs infinite pole based on the tree structure. thinkphp recursion _ PHP Tutorial

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.