Are there any best practices or alternative methods for filtering out only files and not directories in PHP?

When filtering files in PHP, it's common to use functions like `is_file()` or `is_dir()` to distinguish between files and directories. To filter out only files and not directories, you can use the `is_file()` function in combination with a loop to iterate through all items in a directory and only process files.

$directory = '/path/to/directory';

$files = array();

if ($handle = opendir($directory)) {
    while (false !== ($entry = readdir($handle))) {
        if (is_file($directory . '/' . $entry)) {
            $files[] = $entry;
        }
    }
    closedir($handle);
}

print_r($files);