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

WBOY
Release: 2016-06-13 12:42:09
Original
762 people have browsed it

请教一个多维数组递归查找问题
有个无限极分类的数据表
我把数据表分类,生成了多维数组进行保存
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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!