What potential pitfalls should be considered when using FOR loops with arrays in PHP?

One potential pitfall when using FOR loops with arrays in PHP is the risk of accessing elements beyond the array's bounds, which can lead to errors or unexpected behavior. To prevent this, it is important to always check the array's length before accessing elements within the loop.

// Example of using a FOR loop with arrays in PHP with bounds checking
$array = [1, 2, 3, 4, 5];
$array_length = count($array);

for ($i = 0; $i < $array_length; $i++) {
    echo $array[$i] . "\n";
}