Include JUST files in scandir array?

前端 未结 6 2016
刺人心
刺人心 2020-12-05 14:19

I have an array I\'m getting back from scandir, but it contains \".\" and \"..\" and I don\'t want it to.

My code:

$indir =         


        
6条回答
  •  春和景丽
    2020-12-05 14:51

    You can use array_filter.

    $indir = array_filter(scandir('../pages'), function($item) {
        return !is_dir('../pages/' . $item);
    });
    

    Note this filters out all directories and leaves only files and symlinks. If you really want to only exclude only files (and directories) starting with ., then you could do something like:

    $indir = array_filter(scandir('../pages'), function($item) {
        return $item[0] !== '.';
    });
    

提交回复
热议问题