加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php遍历树的常用方法汇总

发布时间:2020-12-12 20:56:11 所属栏目:PHP教程 来源:网络整理
导读:本篇章节讲解php遍历树的常用方法。供大家参考研究。具体如下: 一、递归的深度优先的算法: if (is_file($path)) { $files[] = $path; } $files = array_merge($files,rec_list_files($path));}closedir($dh); } return $files; } function profile

本篇章节讲解php遍历树的常用方法。分享给大家供大家参考。具体如下:

一、递归的深度优先的算法:

if (is_file($path)) { $files[] = $path; } $files = array_merge($files,rec_list_files($path)); } closedir($dh);

}
return $files;
}
function profile($func,$trydir)
{
$mem1 = memory_get_usage();
echo '

----------------------- Test run for '.$func.'() ';
flush();
$time_start = microtime(true);
$list = $func($trydir);
//print_r($list);
$time = microtime(true) - $time_start;
echo 'Finished : '.count($list).' files
';
$mem2 = memory_get_peak_usage();
printf('
Max memory for '.$func.'() : %0.2f kbytes Running time for '.$func.'() : %0.f s
',($mem2-$mem1)/1024.0,$time);
return $list;
}
profile('rec_list_files',"D:wwwserver");
?>

二、递归的深度优先的算法(用了一个栈来实现)

三、非递归的广度优先算法(用了一个队列来实现)

NEXT CHILD } return $files; // end of tree,file not found } function profile($func,$time); return $list; } profile('breadth_first_files',"D:wwwserver"); ?>

希望本文所述对大家的php程序设计有所帮助。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读