欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

请问一个多维数组递归查找有关问题

程序员文章站 2024-01-04 15:50:10
...
请教一个多维数组递归查找问题
有个无限极分类的数据表
我把数据表分类,生成了多维数组进行保存
function getkind($id)
{
if(file_exists($_G['cache'].'kindcache.txt')) //分类缓存是否存在
$str = unserialize(file_get_contents($_G['cache'].'kindcache.txt'));
else
$str = $cache->outkindcache(0); // 生成分类缓存
$data=$this->getkindcache($id,$str); //查找数组
return $data;
}

function getkindcache($id,$str,$data1=array())//递归函数
{
global $_G;
foreach($str as $k=>$v)
{
if($v['kind'] == $id)
{
$data1[] = $v;
}
if(is_array($v['child']))
$this->getkindcache($id,$v['child'],$data1);

}
return $data1;
}
上面的这个递归函数总是返回NULL,不能保存我要返回的数据

标红的是我要查找的数据

Array
(
[0] => Array
(
[uid] => 2
[kind] => 0
[top] => 2
[pagesize] => 15
[name] => 新闻
[sort] => 1
[keywords] =>
[description] =>
[enable] => 1
[html] => 1
[outlink] =>
[model] => news
[modelname] => 新闻模型
[template] => news.html
[templist] => news_list.html
[tempview] => news_view.html
[typedir] => http://localhost/2011-4-30/static/2
请问一个多维数组递归查找有关问题

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频


上一篇:

下一篇: