How can the foreach loop be utilized in PHP to improve code readability and prevent loop-related errors?

When dealing with arrays in PHP, using a foreach loop can greatly improve code readability and prevent loop-related errors compared to traditional for loops. The foreach loop automatically iterates over each element in an array, eliminating the need to manually manage loop counters and array indexes. This can make the code easier to read and understand, reducing the chances of off-by-one errors or other loop-related mistakes.

// Using foreach loop to iterate over an array
$colors = array("red", "green", "blue");

foreach ($colors as $color) {
    echo $color . "<br>";
}