$tree[1] = array('1号',0);
$tree[2] = array('2号',0);
$tree[3] = array('3号',1);
$tree[4] = array('4号',2);
/*
$tree 键是 数据库ID号
$tree[4] = array("4号",2);这里的2是$tree的键
说白了,就是一个无限级分类
我不明白下面递归的 如何执行的???????
*/ function get_childs($id=0){ //$id = 0 判断是否是 顶级分类
$childs = array();
foreach ($tree as $key => $value)
{
if ($id == $value[1]) {
$childs[$key] = $value;
$childs = $childs + get_childs($key);
}
}
return $childs;
}
$tree[2] = array('2号',0);
$tree[3] = array('3号',1);
$tree[4] = array('4号',2);
/*
$tree 键是 数据库ID号
$tree[4] = array("4号",2);这里的2是$tree的键
说白了,就是一个无限级分类
我不明白下面递归的 如何执行的???????
*/ function get_childs($id=0){ //$id = 0 判断是否是 顶级分类
$childs = array();
foreach ($tree as $key => $value)
{
if ($id == $value[1]) {
$childs[$key] = $value;
$childs = $childs + get_childs($key);
}
}
return $childs;
}
function get_childs($id=0){ //$id = 0 判断是否是 顶级分类
$childs = array();//定义子类数组
foreach ($tree as $key => $value)//函数中$tree数组怎么来的?
{
if ($id == $value[1]) { //如果是顶级分类
$childs[$key] = $value;//给$childs数组赋值
$childs = $childs + get_childs($key);//递归调用
}
}
return $childs;
}
$childs = array();//定义子类数组
foreach ($tree as $key => $value)//函数中$tree数组怎么来的?
{
if ($id == $value[1]) { //如果是顶级分类
$childs[$key] = $value;//给$childs数组赋值
$childs = $childs + get_childs($key);//递归调用
}
}
return $childs;
}
/*
$tree 数组是从数据库取得。
$tree[‘本分类ID’] = array('分类名称','父类分类ID')*/
/*
这些代码都是在一个分类 里面 class里
调用的时候直接用
那个function 里面调用的时候
是这样的:*/
function get_childs($id=0){ //$id = 0 判断是否是 顶级分类
$childs = array();
foreach ($this->arr_tree as $key => $value)
{
if ($id == $value[1]) { //是一级分类时
$childs[$key] = $value; //直接返回值 $key 是 分类主键UID的值
$childs = $childs + $this->get_childs($key);
}
}
return $childs;
}$cate = new Cate()return $cate->get_child();