In the context of nested loops in PHP, what are the common pitfalls to watch out for when accessing variables outside of the inner loop?

When accessing variables outside of an inner loop in PHP, a common pitfall is variable scope. Variables declared outside of the inner loop may not be accessible within it due to scope limitations. To solve this issue, you can use the 'global' keyword to access variables declared outside of the loop within the loop.

$outerVariable = 5;

for ($i = 0; $i < 3; $i++) {
    global $outerVariable;
    
    for ($j = 0; $j < 2; $j++) {
        echo $outerVariable;
    }
}