thinkphp implement recursive loop column and follow the method of infinite pole output of tree structure, thinkphp recursive _php tutorial

Source: Internet
Author: User
Tags php template smarty template

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 ...

  • Related Article

    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.