I have some string i have to fix from old code. i have something like this:
$str = 'a-b-x-d-e';
$str = 'bbbb-ccccc-y-ee-fff';
$str = 'aa-ee-z-jjjjjjjj-uuu';
$str = 'aa-ee-z-y-x';
the middle one is (x or y or z) is not valid anymore, and i have to replace it with either "m, n or p"
now, there's plenty way to do this, i was thinking to do:
$list = explode($str);
foreach($list as $k => $v) {
//find the third one and replace it by rebuilding the string
}
but this seem very cumbersome and long to do, is there any faster way?
edit: I can also have the same values at any other position, which these are still valid.