递归地遍历文件夹到多维数组中
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了递归地遍历文件夹到多维数组中相关的知识,希望对你有一定的参考价值。
<?php $tree = dir_tree($dir); function dir_tree($dir) { static $child = false; // Detect the current branch to append files/directories to { $branch =& $tree[$child]; } else { $branch =& $tree; } // Force trailing slash on directory // Find files/directories foreach($items as $key => $item) { // Get basename // always skip dot files if ($base[0] == '.') continue; // If file { $branch[] = $base; $child = false; continue; } // If directory { // Dirty hack to get around PHP's numerical index rules $base = '~'.$base; $child = $base; dir_tree($item); continue; } } // Only return from the root call if ($child === false) return $tree; }
以上是关于递归地遍历文件夹到多维数组中的主要内容,如果未能解决你的问题,请参考以下文章