When using str_replace with arrays() as $search and $replace parameters, the function will evaluate every items in the $search array, for EACH characters of the $subject string. This is important to understand as every "loop" for a given character evaluates the content of the position of the $subject that it is working on at that point.
This results in the function being able to change that character multiple times in one pass (that character from the $subject, against all the items in the $search array.)
A simple example would be the following code/output:
$str = "a b c";
$pattern = array("a","b","a");
$replacement = array("a1","b1","c1");
echo str_replace($pattern, $replacement, $str); // Output : c11 b1 c
The function executes the "search" against ALL items in the search array, for each character in $str. Here is the first "loop" for the first character in $str ("a") :
First is finds "a", which gets replaced with "a1", then it looks for "b", which is not found. Then it looks for "a" again, and replaces the aforementioned replacement ("a"=>"a1") with the mapping "a"=>"c1" which leads to "c11".
Then goes on to the next character in $str.
YOUR EXAMPLE
When the second character in your $str ("b") is searched-against, it gets replaced with "6e" (this is the new state of $str) then following the "loop" that NEW "e" is found in the $search array, and replaced with "6u". At that point, you have "6a 66u". You can extrapolate the rest.
The reason why the first "a"=>"6a" is exact, is that the NEW state of $str after first iteration of the search "loop", that is "6a", will not match any of the other items in the search array.
As per php documentation ( php.net str_replace() ) :
Caution:
Replacement order gotcha.
Because str_replace() replaces left to right, it might replace a previously inserted value when doing multiple replacements.
This behavior has led to very interesting/unexpected results and was not trivial to debug.
Some answers already point to solutions, I wanted to chime-in to provide details about the experienced behavior of php.
Hope this helps, let me know! Cheers