Is there a way to glob() only files?

后端 未结 5 1374
逝去的感伤
逝去的感伤 2020-12-30 21:34

I know that glob can look for all files or only all directories inside a folder :

echo \"All files:\\n\";
$all = glob(\"/*\");
var_dump($all);

echo \"Only d         


        
5条回答
  •  天涯浪人
    2020-12-30 21:57

    I finally found a solution :

    echo "Only files\n";
    $files = array_filter(glob("/*"), 'is_file');
    var_dump($files);
    

    But take care, array_filter will preserve numeric keys : use array_values if you need to reindex the array.

提交回复
热议问题