PHP Function Glob
A php function glob is used to search for filenames and directories based on pattern. The function returns an array of filenames if it finds any. It also ignores hidden files like.gitignore and dotfiles.
The php function glob accepts two parameters in its implementation: the $pattern and the $flags. The first parameter is the pattern of file or folder that you want to search. The second parameter can include additional settings that influence the behavior of the glob function. For example, you can set the flags to GLOB_MARK to add a slash with each returned item or GLOB_NOSORT to prevent sorting.
Another setting you can use is the GLOB_BRACE to expand characters from a group to match e.g. 'a,b,c' matches 'jpg,gif,png'. This is useful if you want to find image files. You can learn more about these settings by reading the glob manual page.
Using the php function glob can be a little slow because it needs to build an array of files and then return it. It is possible to speed up the process by using alternatives such as readdir(), foreach() and array_flip().
However, the advantage of glob() is that it handles symbolic filesystem links nicely. This makes it better than other functions that do not handle symlinks such as scandir() and rglob().