$replacedString = str_replace(array_keys($array1), $array1, $externalVariableString);
I have an entire array above that called $championToIdConversionArray
, it has about 650 switches, it looks something like this
$array1 = array(
"1" => "Banana",
"12" => "Monkey",
"2" => "Apple",
"121" => "Human"
);
Now if I let script parse numbers "121", it won't say "Human", but "BananaAppleBanana". Could someone help with this? How could I force the small one-liner above, the swap only entire matches, not just parts of it?
This isn't actual example, as I said, I made PHP script which generated gigantic array saving me lots of time, it swaps ID's for names and it has around 700 positions. So instead of "Peter" I'm seeing "JackJoshJohn". Because Peter is let's say 123, and Jack, Josh and John are first in the array, before Peter.