$search = array('A', 'B', 'C', 'D', 'E');
$replace = array('B', 'C', 'D', 'E', 'F');
$subject = 'A';
$trans = array('A' => 'B','B'=>'C','C'=>'D','D'=>'E','E'=>'F');
echo str_replace($search, $replace, $subject);
echo "<br/>";
echo strtr($subject,$trans);
Output: F
B
When using str_replace I get F, using strtr i get B
As far I am getting this, for str_replace: It replaces from left to right, so A gets replaced with B without marking the position was already replaced, so again finds B which is replaced by C and so on to get value F.
For strtr: I replaces A with B and remembers it has replaced at that position,
Am i getting this correctly? could someone explain to me?
Yes, that is correct.
str_replace()does its replacements sequentially, whereasstrtr()works through each character in the string and replaces it only once.