What are the potential pitfalls of using the glob() function in PHP for file filtering?

The potential pitfall of using the glob() function in PHP for file filtering is that it does not support complex filtering criteria, such as filtering by file extension or file size. To solve this issue, you can use the array_filter() function in combination with glob() to apply custom filtering criteria.

$files = glob('path/to/directory/*');
$filteredFiles = array_filter($files, function($file) {
    return pathinfo($file, PATHINFO_EXTENSION) == 'txt'; // Filter files by extension
});