What best practices should be followed when using for loops in PHP to iterate through arrays?

When using for loops in PHP to iterate through arrays, it is important to follow best practices to ensure efficient and error-free code. One key practice is to use the count() function to determine the length of the array and iterate up to that length. Additionally, using the $key => $value syntax in the loop can provide access to both the index and value of each element in the array. Finally, make sure to properly handle any edge cases, such as empty arrays, to prevent errors.

// Example of iterating through an array using a for loop
$array = [1, 2, 3, 4, 5];
$array_length = count($array);

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