What advantage does using a foreach loop offer over a for loop when working with arrays in PHP?

Using a foreach loop offers the advantage of simplicity and readability when working with arrays in PHP. It eliminates the need to manually manage array indexes and count elements, making the code cleaner and easier to understand. Additionally, foreach loops automatically iterate over each element of the array, reducing the risk of off-by-one errors that can occur with traditional for loops.

// Using a foreach loop to iterate over an array
$colors = ['red', 'green', 'blue'];

foreach ($colors as $color) {
    echo $color . "\n";
}