Skip to content

Instantly share code, notes, and snippets.

@kodie
Last active April 24, 2024 12:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kodie/4865db468da7f6d4d180a0667fec2cab to your computer and use it in GitHub Desktop.
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
<?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