What are common pitfalls when using nested while loops in PHP?

Common pitfalls when using nested while loops in PHP include forgetting to increment the loop counters properly, leading to infinite loops, and complexity issues when dealing with multiple nested loops. To avoid these pitfalls, always make sure to properly increment loop counters and consider refactoring the code to reduce the complexity of nested loops.

// Example of properly incrementing loop counters in nested while loops
$outerCounter = 0;
$innerCounter = 0;

while ($outerCounter < 3) {
    echo "Outer loop iteration: $outerCounter\n";
    
    while ($innerCounter < 2) {
        echo "Inner loop iteration: $innerCounter\n";
        $innerCounter++;
    }
    
    $innerCounter = 0; // Reset inner counter for the next iteration
    $outerCounter++;
}