获取大类下的所有小类

WBOY
Release: 2016-06-23 14:17:58
Original
985 people have browsed it


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、不知道希望的结果

Related labels:
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!