How can the glob function in PHP be used to retrieve folder contents?

The glob function in PHP can be used to retrieve the contents of a folder by providing a pattern to match the files or directories. This function returns an array of file names or directory names that match the specified pattern. By using glob, you can easily retrieve all the files or directories within a folder without having to manually iterate through each item.

// Retrieve all files in a folder
$files = glob('path/to/folder/*');

// Loop through the files and do something with them
foreach($files as $file) {
    echo $file . "<br>";
}