How can the "each()" function be replaced with a "foreach" loop in PHP code?

The "each()" function in PHP is deprecated as of PHP 7.2 and removed in PHP 8. To replace it with a "foreach" loop, you can iterate over the array directly using the foreach loop syntax. This loop allows you to iterate over each key-value pair in the array without the need for the deprecated "each()" function.

// Using foreach loop to replace each() function
$array = ['a' => 1, 'b' => 2, 'c' => 3];

foreach ($array as $key => $value) {
    echo "Key: $key, Value: $value\n";
}