Last active
August 24, 2024 03:05
-
-
Save kodie/4865db468da7f6d4d180a0667fec2cab to your computer and use it in GitHub Desktop.
Array map function that allows you to change keys as well as values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Array map function that allows you to change keys as well as values | |
// Example: array_map_assoc(function($k, $v) { return array($k => $v); }, $array); | |
function array_map_assoc(callable $f, array $a) { | |
return array_merge(...array_map($f, array_keys($a), $a)); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
does not work, array keys are changed not leaved oroiginal