日期:2014-05-17  浏览次数:20410 次

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