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