Include JUST files in scandir array?

前端 未结 6 2049
刺人心
刺人心 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:59

    I am aware erknrio provided an answer for this, but here is a cleaner way of getting an array of files without directories (modified to be more efficient):

    $dirPath = 'dashboard';
    
    $dir = scandir($dirPath);
    
    foreach($dir as $index => &$item)
    {
        if(is_dir($dirPath. '/' . $item))
        {
            unset($dir[$index]);
        }
    }
    
    $dir = array_values($dir);
    

提交回复
热议问题