How can the glob function in PHP be used to specify a different directory for accessing files?

To specify a different directory for accessing files using the glob function in PHP, you can simply provide the path to the desired directory as an argument to the function. This allows you to search for files matching a specific pattern within a specific directory, rather than the default directory.

$files = glob('/path/to/directory/*.txt');
foreach($files as $file) {
    echo $file . "<br>";
}