Isn't that much easier? Eager to learn how the method works? If yes, then let's get on with it.

glob() supports a total of two arguments, with the second argument being optional. The first argument is the path to the folder, however, it's a bit more powerful than that.

Step 1. The First Argument

This first argument supports a pattern. This means that you can limit the search to specific filetypes or even multiple directories at the same time by using multiple asterixes "*". Let's assume that you have a website that allows users to upload images (just because I read this). Each user has his/her own folder within the folder "userImages." Inside these folder are two additional folders, called "HD" and "TN," for high definition (full-sized) images, and for thumbnails. Let's imagine that you want to loop through all your users' "TN" folders and print the filenames. This would require a relatively large snippet of code if you were to use open_dir(); however, with glob(), it's easy.