11
I was analyzing the way functions behave strtr
and str_replace
And I noticed that, at first glance, they both seem to do exactly the same thing.
Example:
$translators = [
'da hora' => 'bacana',
'ser' => 'é',
];
$str = 'O Stack Overflow ser um site da hora';
echo str_replace(array_keys($translators), $translators, $str);
// O Stack Overflow é um site bacana
echo strtr($str, $translators);
//O Stack Overflow é um site bacana
Apart from the way the function parameters are passed, there is some considerable difference between them, to the point of having to decide which to use for each specific case?
Or both do the same thing?
And, if they do, why exist the two?
see if this helps you: http://stackoverflow.com/questions/8177296/when-to-use-strtr-vs-str-replace if you don’t understand, ask for a reply format
– kabstergo