How can a beginner effectively implement the glob() function to filter out only PDF files in a PHP script?

To filter out only PDF files using the glob() function in PHP, a beginner can specify the file extension pattern as "*.pdf" in the glob() function call. This will return an array of file paths that only point to PDF files in the specified directory.

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