What are common pitfalls when working with arrays and loops in PHP?

One common pitfall when working with arrays and loops in PHP is not properly initializing variables before using them within a loop. This can lead to unexpected behavior or errors. To solve this issue, make sure to initialize any variables outside of the loop before using them within the loop.

// Incorrect way - not initializing $sum before using it in the loop
$numbers = [1, 2, 3, 4, 5];
$sum = 0;

foreach ($numbers as $number) {
    $sum += $number;
}

echo $sum; // Output: 15
```

```php
// Correct way - initializing $sum before using it in the loop
$numbers = [1, 2, 3, 4, 5];
$sum = 0;

foreach ($numbers as $number) {
    $sum += $number;
}

echo $sum; // Output: 15