Creates a Closure that transforms the keys of an array or iterable. Setting a key to an existing index overwrites the value already there.
/**
* @param callable $func
* @return Closure(iterable<int|string, mixed>):(array<int|string, mixed>|\Generator<int|string, mixed>)
*/
Arrays\mapKey(callable $func): ClosureWhen Arrays\mapKey() is called, it returns the following Closure which can be used like a regular function.
/**
* @param iterable<int|string, mixed> $source
* @return array<int|string, mixed>|\Generator<int|string, mixed>
*/
$function (iterable $source): array|\GeneratorThis can be used to create a simple closure which can be used as a regular function.
$prefix = Arrays\mapKey(fn($k) => "__$k");
print_r($prefix(['a' => 1, 'b' => 2]));
// ['__a' => 1, '__b' => 2]This can be called inline using currying.
print_r(Arrays\mapKey('strtoupper')(['a' => 1])); // ['A' => 1]