dedecms函数分享之获取某一栏目所有子栏目


以前从来没写过递归(其实想想,对算法完全没概念),刚好有这个需求,试着写了一下,发现也挺容易的,特别记录一下。

数据库是dedecms默认的,dede_arctype是保存栏目的表,reid是栏目的父级栏目id。

复制代码 代码如下:

$array = array();
get_sons($type, $array);

var_dump($array);

function get_sons($type, &$current_array){
    $result = mysql_query("select id from dede_arctype where reid = {$type}");
    while($row = mysql_fetch_assoc($result)){
        $current_array[] = $row['id'];
        get_sons($row['id'], $current_array);
    }
}


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3