Is there a shorthand for the following code:
$result = array_combine(array_map(fn($elem) => "key_$elem", $array), array_map(fn($elem) => "value_$elem", $array));
I do not like the idea (from readability point of view) of having to use array map twice on the same array and then combining the intermediate results.
3
Answers
Thanks for the suggestions. However, I have reached a solution that I like more:
PHP Sandbox
You can use
array_reduce
https://www.php.net/manual/en/function.array-reduce.php
PHP Sandbox
I’d just define simple function, like that: