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

Potential pitfalls when using nested for loops in PHP include increased complexity, decreased readability, and potential performance issues, especially with large datasets. To avoid these pitfalls, consider using alternative looping structures like foreach loops or array functions when possible. Additionally, make sure to optimize the loop conditions and logic to minimize unnecessary iterations.

// Original code snippet with nested for loops
for ($i = 0; $i < count($array1); $i++) {
    for ($j = 0; $j < count($array2); $j++) {
        // Nested loop logic
    }
}
```

```php
// Revised code snippet using foreach loops
foreach ($array1 as $item1) {
    foreach ($array2 as $item2) {
        // Nested loop logic
    }
}