What are the potential issues with using glob() function in PHP for recursive directory operations?

One potential issue with using the glob() function in PHP for recursive directory operations is that it does not natively support recursion. This means that it can only retrieve files from the specified directory and not its subdirectories. To solve this issue, you can create a custom recursive function that iterates through all directories and subdirectories to retrieve the files.

function recursive_glob($dir){
    $files = glob($dir . '/*');
    
    foreach($files as $file){
        if(is_dir($file)){
            $files = array_merge($files, recursive_glob($file));
        }
    }
    
    return $files;
}

$files = recursive_glob('path/to/directory');