Skip to content

Instantly share code, notes, and snippets.

@kodie
Last active August 24, 2024 03:05
Show Gist options
  • 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));
}
?>
@kriit24
Copy link

kriit24 commented Aug 24, 2024

does not work, array keys are changed not leaved oroiginal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment