What are the advantages of using foreach loop over while loop in PHP for array iteration?

Using a foreach loop over a while loop in PHP for array iteration is advantageous because it simplifies the syntax and makes the code more readable. The foreach loop automatically iterates over each element in the array without the need for manual indexing or incrementing. This can lead to cleaner and more concise code, reducing the chances of errors and making the code easier to maintain.

// Using foreach loop for array iteration
$colors = array("red", "green", "blue");

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