How can the use of in_array() enhance the functionality of file searching in PHP, especially when combined with glob()?

When searching for files using glob() in PHP, we may need to check if a specific file extension or name exists within the search results. By using in_array() in combination with glob(), we can easily check if a file matches our criteria and enhance the functionality of our file searching process.

$files = glob('path/to/directory/*'); // Get an array of files in the directory
$searchTerm = 'example.txt'; // File we are searching for

if (in_array($searchTerm, $files)) {
    echo "File found: $searchTerm";
} else {
    echo "File not found: $searchTerm";
}