mapKey()
The mapKey() method all similar to map(), but this applies to keys
<?php use kim\present\utils\arrays\ArrayUtils;
$arrayUtils = ArrayUtils::from(range(1,5));
//Squared all elements
$arrayUtils->mapKey(function($num){ return "$num * $num"; });
// expected output: [
// "1 * 1" => 1,
// "2 * 2" => 2,
// "3 * 3" => 3,
// "4 * 4" => 4,
// "5 * 5" => 5
//]Syntax
$arrayUtils->mapKey(callable $callback) : ArrayUtils;Parameter
Return value
Prefixing
References
map()Last updated