Home  >  Article  >  Backend Development  >  获取大类下的所有小类

获取大类下的所有小类

WBOY
WBOYOriginal
2016-06-23 14:17:58995browse


function get_children($tid){
        global $db,$table;
        if($row = $db->getAll("SELECT tid FROM `{$table}article_type` WHERE pid = $tid")){
                $arr = array();
                foreach ($row as $k => $v){
                        $arr[$v['tid']] = $v['tid'];
                            get_children($v['tid']);
                }
                $tids = implode(',', $arr);
                return $tids;
        }else{
                return $tid;
        }
}

递归获取大类下的所有子类,想最后返回这样的结果:2,3,4,5,6

上段代码有问题,最后取得的结果是这样的:23,4,5,6

应该怎么改呢


回复讨论(解决方案)

递归调用 get_children($v['tid']); 没有接收返回值

var_export($row);
贴出结果

应该怎么修改下

1、不知道原始数据的格式
2、不知道希望的结果

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
Previous article:数据库连接错误,如何修改Next article:PHP怎么样?