How can the foreach loop be correctly used to iterate through arrays in PHP?

To iterate through arrays in PHP using a foreach loop, you need to specify the array you want to iterate through and a variable to hold each value in the array during each iteration. The foreach loop automatically loops through each element in the array until all elements have been processed. You can then perform any desired operations on each element within the loop.

// Example array
$colors = array("red", "green", "blue");

// Iterate through the array using foreach loop
foreach($colors as $color) {
    echo $color . "<br>";
}