首页 / PHP / 请教一个多维数组递归查找问题
请教一个多维数组递归查找问题
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了请教一个多维数组递归查找问题,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含15239字,纯文字阅读大概需要22分钟。
内容图文
![请教一个多维数组递归查找问题](/upload/InfoBanner/zyjiaocheng/196/50ccd23e3d554d48a1df187200b3eb8a.jpg)
我把数据表分类,生成了多维数组进行保存
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
[grade] => 1
[kindtype] => 1
[child] => Array
(
[0] => Array
(
[uid] => 1
[kind] => 2
[top] => 1
[pagesize] => 15
[name] => 产品展示
[sort] => 0
[keywords] =>
[description] =>
[enable] => 1
[html] => 1
[outlink] =>
[model] => product
[modelname] => 产品模型
[template] => product.html
[templist] => product_list.html
[tempview] => product_view.html
[typedir] => http://localhost/2011-4-30/static/1
[grade] => 1
[kindtype] => 1
[child] => Array
(
[0] => Array
(
[uid] => 15
[kind] => 1
[top] => 1
[pagesize] => 15
[name] => 橡胶制品
[sort] => 0
[keywords] =>
[description] =>
[enable] => 1
[html] => 1
[outlink] =>
[model] => product
[modelname] => 产品模型
[template] => product.html
[templist] => product_list.html
[tempview] => product_view.html
[typedir] => http://localhost/2011-4-30/static/1/15/list_1.html
[grade] => 1
[kindtype] => 0
[child] =>
)
)
)
[1] => Array
(
[uid] => 3
[kind] => 2
[top] => 3
[pagesize] => 30
[name] => 图片展示
[sort] => 0
[keywords] =>
[description] =>
[enable] => 1
[html] => 1
[outlink] =>
[model] => images
[modelname] => 图片模型
[template] => images.html
[templist] => images_list.html
[tempview] => images_view.html
[typedir] => http://localhost/2011-4-30/static/3/list_1.html
[grade] => 1
[kindtype] => 0
[child] => Array
(
[0] => Array
(
[uid] => 17
[kind] => 3
[top] => 3
[pagesize] => 15
[name] => 测试
[sort] => 0
[keywords] => 1111
[description] => 2222
[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/3/17/list_1.html
[grade] => 0
[kindtype] => 0
[child] =>
)
[1] => Array
(
[uid] => 18
[kind] => 3
[top] => 3
[pagesize] => 15
[name] => 测试
[sort] => 0
[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/3/18/list_1.html
[grade] => 0
[kindtype] => 0
[child] =>
)
[2] => Array
(
[uid] => 19
[kind] => 3
[top] => 3
[pagesize] => 15
[name] => 测试
[sort] => 0
[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/3/19/list_1.html
[grade] => 0
[kindtype] => 0
[child] =>
)
)
)
回复讨论(解决方案)
[3] => Array
(
[uid] => 7
[kind] => 2
[top] => 2
[pagesize] => 15
[name] => 法国新闻
[sort] => 0
[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/7
[grade] => 1
[kindtype] => 1
[child] =>
)
)
[4] => Array
(
[uid] => 8
[kind] => 2
[top] => 2
[pagesize] => 15
[name] => 中国新闻
[sort] => 0
[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/8/list_1.html
[grade] => 1
[kindtype] => 0
[child] =>
)
[5] => Array
(
[uid] => 9
[kind] => 2
[top] => 2
[pagesize] => 15
[name] => 俄罗斯新闻
[sort] => 0
[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/9/list_1.html
[grade] => 1
[kindtype] => 0
[child] =>
)
[6] => Array
(
[uid] => 10
[kind] => 2
[top] => 2
[pagesize] => 15
[name] => 英国新闻
[sort] => 0
[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/10/list_1.html
[grade] => 1
[kindtype] => 0
[child] =>
)
)
)
[1] => Array
(
[uid] => 4
[kind] => 0
[top] => 4
[pagesize] => 15
[name] => 信息分类
[sort] => 6
[keywords] =>
[description] =>
[enable] => 1
[html] => 1
[outlink] =>
[model] => info
[modelname] => 分类模型
[template] => info.html
[templist] => info_list.html
[tempview] => info_view.html
[typedir] => http://localhost/2011-4-30/static/4/list_1.html
[grade] => 1
[kindtype] => 0
[child] => Array
(
[0] => Array
(
[uid] => 5
[kind] => 4
[top] => 4
[pagesize] => 15
[name] => 旅游摄影
[sort] => 0
[keywords] => 旅游摄影
[description] => 旅游摄影
[enable] => 1
[html] => 1
[outlink] =>
[model] => info
内容总结
以上是互联网集市为您收集整理的请教一个多维数组递归查找问题全部内容,希望文章能够帮你解决请教一个多维数组递归查找问题所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。