亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

php遞歸實(shí)現(xiàn)無(wú)限分類的方法

 更新時(shí)間:2015年07月28日 14:38:47   作者:yak  
這篇文章主要介紹了php遞歸實(shí)現(xiàn)無(wú)限分類的方法,涉及php遞歸遍歷的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了php遞歸實(shí)現(xiàn)無(wú)限分類的方法。分享給大家供大家參考。具體如下:

<?php
$rows = array(
  array(
    'id' => 1,
    'name' => 'dev',
    'parentid' => 0
  ),
  array(
    'id' => 2,
    'name' => 'php',
    'parentid' => 1
  ),
  array(
    'id' => 3,
    'name' => 'smarty',
    'parentid' => 2
  ),
  array(
    'id' => 4,
    'name' => 'life',
    'parentid' => 0
  ),
  array(
    'id' => 5,
    'name' => 'pdo',
    'parentid' => 2
  ),
  array(
    'id' => 6,
    'name' => 'pdo-mysql',
    'parentid' => 5
  ),
  array(
    'id' => 7,
    'name' => 'java',
    'parentid' => 1
  )
);
// 72648
// 84072
function findChild(&$arr,$id){
  $childs=array();
   foreach ($arr as $k => $v){
     if($v['parentid']== $id){
       $childs[]=$v;
     }
  }
  return $childs;
}
function build_tree($root_id){
  global $rows;
  $childs=findChild($rows,$root_id);
  if(empty($childs)){
    return null;
  }
  foreach ($childs as $k => $v){
    $rescurTree=build_tree($v[id]);
    if( null !=  $rescurTree){ 
    $childs[$k]['childs']=$rescurTree;
    }
  }
  return $childs;
}
$tree=build_tree(0);
echo memory_get_usage();
print_r($tree);
?>

希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論