What are some potential pitfalls of using nested loops in PHP for generating random text?

One potential pitfall of using nested loops in PHP for generating random text is that it can lead to inefficient code and slow performance, especially if the loops have a large number of iterations. To solve this issue, you can consider using alternative methods such as recursion or utilizing built-in PHP functions for generating random text.

// Example of using recursion to generate random text without nested loops
function generateRandomText($length, $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') {
    if ($length <= 0) {
        return '';
    }
    
    $randomChar = $characters[rand(0, strlen($characters) - 1)];
    
    return $randomChar . generateRandomText($length - 1, $characters);
}

// Usage
echo generateRandomText(10);