What is the purpose of using str_replace() in a foreach loop in this PHP script?
The purpose of using str_replace() in a foreach loop in this PHP script is to iterate over an array of strings and replace a specific substring with a new value in each string. This allows for bulk replacement of substrings in multiple strings at once.
// Example PHP code snippet implementing the fix
$strings = ["Hello World", "Lorem Ipsum", "Foo Bar"];
$search = "o";
$replace = "0";
foreach ($strings as &$string) {
$string = str_replace($search, $replace, $string);
}
print_r($strings);