How can the strtr function be used as an alternative to str_replace in PHP?
The strtr function in PHP can be used as an alternative to str_replace when you need to replace multiple occurrences of different substrings with different replacements in a string. It allows you to specify an array where the keys are the substrings to be replaced and the values are the replacements. This can be more efficient and cleaner than using multiple str_replace calls.
// Using strtr function as an alternative to str_replace
$string = "Hello, world!";
$replacements = array("Hello" => "Hi", "world" => "universe");
$new_string = strtr($string, $replacements);
echo $new_string; // Output: Hi, universe!