Skip to content

Commit

Permalink
Add drupal_map_assoc (#83)
Browse files Browse the repository at this point in the history
Co-authored-by: Darren Oh <[email protected]>
  • Loading branch information
mglaman and darrenoh authored Nov 2, 2023
1 parent e5f8590 commit 056bb85
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/functions/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,17 @@ function filter_xss_bad_protocol(string $string, bool $decode = true): string
{
return UrlHelper::filterBadProtocol($string);
}


/**
* @param array<string|int> $array
* @return array<string|int, mixed>
*/
function drupal_map_assoc(array $array, ?callable $function = null): array
{
$array = array_combine($array, $array);
if ($function !== null) {
$array = array_map($function, $array);
}
return $array;
}

0 comments on commit 056bb85

Please sign in to comment.