How can PHP be used to replace keys in a string with corresponding values from an array?

To replace keys in a string with corresponding values from an array in PHP, we can use the `str_replace()` function. This function takes three parameters: an array of keys to be replaced, an array of corresponding values, and the original string. It then replaces all occurrences of the keys in the string with their corresponding values.

$keys = array('key1', 'key2', 'key3');
$values = array('value1', 'value2', 'value3');
$string = 'Replace key1 with value1, key2 with value2, and key3 with value3';

$new_string = str_replace($keys, $values, $string);
echo $new_string;