Home  >  Article  >  php教程  >  ThinkPHP实现递归无级分类代码少,thinkphp递归

ThinkPHP实现递归无级分类代码少,thinkphp递归

WBOY
WBOYOriginal
2016-06-13 08:57:121204browse

ThinkPHP实现递归无级分类——代码少,thinkphp递归

具体代码如下:

/**
*  无级递归分类
*  @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 .= '<option value="' . $value['class_id'] . '">' . $tag . $value['class_name'] . '</option>';
    $tree .= recursiveAssort($value['class_id'], $tag . '&emsp;');
  }
  return $tree;
}

以上代码就是用ThinkPHP实现递归无级分类的全部内容,希望大家喜欢。

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