Home > Backend Development > PHP Tutorial > PHP implements levelless recursive classification (ThinkPHP framework)

PHP implements levelless recursive classification (ThinkPHP framework)

PHP中文网
Release: 2016-08-08 09:19:44
Original
1343 people have browsed it

PHP implements stepless recursive classification (ThinkPHP framework):

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

The above is the content of PHP implementing stepless recursive classification (ThinkPHP framework). For more related content, please pay attention to the PHP Chinese website (www.php .cn)!


Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template