What are the potential drawbacks of not using a recursive function when searching through directories in PHP?

When searching through directories in PHP, not using a recursive function can lead to limited search depth, making it difficult to search through nested directories. To solve this issue, a recursive function can be used to traverse through directories and subdirectories effectively.

function searchDirectory($dir) {
    $files = scandir($dir);
    
    foreach($files as $file) {
        if ($file == '.' || $file == '..') {
            continue;
        }
        
        echo $file . "<br>";
        
        if (is_dir($dir . '/' . $file)) {
            searchDirectory($dir . '/' . $file);
        }
    }
}

// Usage
searchDirectory('/path/to/directory');