<?php
function ls($dir) {
    $arr = array();
    foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)) as $v) {
        $type = ($v->isDir()) ? '/' : '';
        $arr[] = $v->getRealPath() . $type;
    }
    return array_unique($arr);
}
var_export(ls('/var/www'));

作者:eechen
链接:https://www.zhihu.com/question/64329927/answer/219229494
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。