What are the advantages of using strtr() over str_replace() for text replacement in PHP?

When it comes to text replacement in PHP, using the strtr() function can be more efficient than using str_replace(). This is because strtr() is optimized for replacing multiple occurrences of different strings in a single pass, while str_replace() requires multiple passes for each replacement. Additionally, strtr() allows for case-insensitive replacements and can handle arrays of search and replace pairs.

// Using strtr() for text replacement
$string = "Hello World";
$replacements = array("Hello" => "Hi", "World" => "Universe");
$newString = strtr($string, $replacements);

echo $newString; // Output: Hi Universe