What is the correct way to use foreach loops in PHP when iterating through arrays?

When using foreach loops in PHP to iterate through arrays, it is important to remember that the key and value variables must be specified in the loop declaration. This allows you to access both the key and value of each element in the array during the iteration. By including both variables, you can effectively loop through the array and perform operations on each element as needed.

$fruits = array("apple", "banana", "orange");

foreach ($fruits as $key => $value) {
    echo "Key: " . $key . ", Value: " . $value . "<br>";
}