At the moment I am doing a foreach
over the array, and creating a new array as I go. For example:
$newMap = [];
foreach ($oldMap as $key => $value) {
// Apply some complex logic to $value to extract a string
$newString = my_value_processor($value);
$newkey = $key + $newString;
$newMap[$newKey] = $value;
}
I have the feeling I should be able to accomplish this with array_map()
, or possibly array_walk()
, and that it would be more efficient, but I can't seem to make it work.
EDIT: In the example above, the code was simplified to show that the $newKey is dependent on $value. The actuality, $value is a sub-array, and I apply some complex logic to it to extract a string. I have updated the example above to demonstrate that.