Assume I have an array:
$origin = ['value1', 'value2', 'value3', 'value4'];
and a replace map array:
$replace_map = [
'value1' => 'replace1',
'value2' => 'replace2',
'value8' => 'replace8',
];
I want to replace the $origin array and expect the result to be:
$result = myReplace($origin, $replace_map);
$result = ['replace1', 'replace2', 'value3', 'value4'];
I can loop $origin and for each items lookup $replace_map by array_key_exists, and replace it with the value in $replace_map,
But I think this is not the best way, it sounds not efficient.
Is there better way to do this?
Further more, if the origin values are all integers, but some are negative, but the keys in map array are all positive,
like:
$origin = [-12345, 23456];
$map = [12345 => 98765];
also need change -12345 to -98765.