What are the potential pitfalls of using arrays in PHP within nested loops like foreach?

When using arrays in nested loops like foreach in PHP, a potential pitfall is that modifying the array within the inner loop can affect the iteration of the outer loop. To solve this issue, you can create a copy of the array before entering the inner loop to avoid unintended side effects.

$originalArray = [1, 2, 3, 4, 5];

foreach ($originalArray as $outerItem) {
    $copyArray = $originalArray; // Create a copy of the original array
    foreach ($copyArray as $innerItem) {
        // Inner loop operations
    }
}