What are common errors when using a For loop in PHP, especially when dealing with arrays?

One common error when using a For loop in PHP, especially with arrays, is accessing elements beyond the array's bounds. This can lead to "Undefined offset" errors. To avoid this, always ensure that the loop counter stays within the array's length by using the count() function to get the array size.

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

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