What best practices should be followed when filtering files in a directory using PHP functions like array_filter?

When filtering files in a directory using PHP functions like array_filter, it's important to ensure that the filtering criteria are clear and specific to avoid unintended results. One common approach is to use the is_file() function within the array_filter callback to only include files in the resulting array.

$directory = '/path/to/directory';
$files = array_filter(scandir($directory), function($file) use ($directory) {
    return is_file($directory . '/' . $file);
});