請教一個多維陣列遞迴尋找問題

來源:互聯網
上載者:User
有個無限極分類的資料表
我把資料表分類,產生了多維陣列進行儲存
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

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.