Home >php教程 >php手册 >dedecms函数分享之获取某一栏目所有子栏目

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

WBOY
WBOYOriginal
2016-06-13 09:34:56887browse

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

数据库是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);
    }
}

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:浅谈discuz密码加密的方式Next article:smarty