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

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

WBOY
WBOYOriginal
2016-06-13 12:23:24983browse

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')->where("class_pid = <span style="color: #800080;">$assortPid</span>")->field('class_id, class_name')-><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="' . <span style=" color:>$value['class_id'] . '">' . <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>

 

Statement:
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