3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function replaceString($string) { $array1 = ['mp', 'tm', 'de']; $array2 = ['MAP', 'TM', "DECIMAL"]; $first = substr($string, 0, -2); $last = substr($string, -2); $split = [ 'start' => $first, 'end' => $last, ]; foreach ($array1 as $key => $val) { if ($val == $split['end']) { $word = $split['start'].$array2[$key]; return $word; } } } $mystring = "samplemp"; echo replaceString($mystring)."\n";
based on rZDiJ
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.0
sampleMAP