You can use strtr
.
$trans = array("A" => "AE","B" => "AD", "C"=>"AC","D"=>"AB","E"=>"AA");
echo strtr("CAB", $trans); // outputs "ACAEAD"
For the reverse function, just array_flip
the original array.
$trans2 = array_flip($trans);
echo strtr("ACAEAD", $trans); // outputs "CAB"