What are the potential pitfalls of using nested for loops in PHP, as seen in the provided code snippet?

Using nested for loops in PHP can lead to performance issues, especially if the loops iterate over a large dataset. Each additional nested loop increases the complexity of the algorithm, potentially leading to longer execution times. To avoid these pitfalls, consider alternative approaches such as using array functions or optimizing the loops to reduce unnecessary iterations.

// Example of refactored code without nested loops
$array1 = [1, 2, 3];
$array2 = [4, 5, 6];

foreach ($array1 as $item1) {
    foreach ($array2 as $item2) {
        // Perform operations using $item1 and $item2
    }
}