Home Backend Development PHP Tutorial PHP实现无级递归分门别类(ThinkPHP框架)

PHP实现无级递归分门别类(ThinkPHP框架)

Jun 13, 2016 pm 12:23 PM
class tree

PHP实现无级递归分类(ThinkPHP框架)

<span style="color: #008000;">/*</span><span style="color: #008000;">**   无级递归分类*   @param   int     $assortPid   要查询分类的父级id*   @param   mixed   $tag         上下级分类之间的分隔符*   @return  string  $tree        返回的分类树型结构结果 *</span><span style="color: #008000;">*/</span><span style="color: #0000ff;">function</span> recursiveAssort(<span style="color: #800080;">$assortPid</span>, <span style="color: #800080;">$tag</span> = ''<span style="color: #000000;">){       </span><span style="color: #800080;">$assort</span> = M('goods_class')-&gt;where("class_pid = <span style="color: #800080;">$assortPid</span>")-&gt;field('class_id, class_name')-&gt;<span style="color: #000000;">select();    </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$assort</span> <span style="color: #0000ff;">as</span> <span style="color: #800080;">$value</span><span style="color: #000000;">) {        </span><span style="color: #800080;">$tree</span> .= '<option value="' . &lt;span style=" color:>$value['class_id'] . '"&gt;' . <span style="color: #800080;">$tag</span> . <span style="color: #800080;">$value</span>['class_name'] . '</option>'<span style="color: #000000;">;        </span><span style="color: #800080;">$tree</span> .= recursiveAssort(<span style="color: #800080;">$value</span>['class_id'], <span style="color: #800080;">$tag</span> . ' '<span style="color: #000000;">);    }    </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$tree</span><span style="color: #000000;">;}</span>
Copy after login

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use classes and methods in Python How to use classes and methods in Python Apr 21, 2023 pm 02:28 PM

How to use classes and methods in Python

Replace the class name of an element using jQuery Replace the class name of an element using jQuery Feb 24, 2024 pm 11:03 PM

Replace the class name of an element using jQuery

What does class mean in python? What does class mean in python? May 21, 2019 pm 05:10 PM

What does class mean in python?

How SpringBoot encrypts and protects class files through custom classloader How SpringBoot encrypts and protects class files through custom classloader May 11, 2023 pm 09:07 PM

How SpringBoot encrypts and protects class files through custom classloader

Use tree to generate a file directory tree for display Use tree to generate a file directory tree for display Mar 01, 2024 pm 05:46 PM

Use tree to generate a file directory tree for display

Methods of predefined Class objects in java Methods of predefined Class objects in java Jul 01, 2023 pm 06:41 PM

Methods of predefined Class objects in java

Detailed explanation of PHP Class usage: Make your code clearer and easier to read Detailed explanation of PHP Class usage: Make your code clearer and easier to read Mar 10, 2024 pm 12:03 PM

Detailed explanation of PHP Class usage: Make your code clearer and easier to read

Vue error: Unable to use v-bind to bind class and style correctly, how to solve it? Vue error: Unable to use v-bind to bind class and style correctly, how to solve it? Aug 26, 2023 pm 10:58 PM

Vue error: Unable to use v-bind to bind class and style correctly, how to solve it?

See all articles