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

WBOY
發布: 2016-06-13 12:42:09
原創
762 人瀏覽過

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

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!