What are some common pitfalls when working with nested for loops in PHP?

One common pitfall when working with nested for loops in PHP is accidentally reusing the same loop variable in both loops, leading to unexpected behavior or errors. To solve this issue, make sure to use different loop variables for each nested loop to avoid conflicts.

// Incorrect nested for loops
for ($i = 0; $i < 5; $i++) {
    for ($i = 0; $i < 3; $i++) {
        echo "($i, $j) ";
    }
}

// Correct nested for loops
for ($i = 0; $i < 5; $i++) {
    for ($j = 0; $j < 3; $j++) {
        echo "($i, $j) ";
    }
}