php array map exemple code example
Example 1: php map array
function cube($number)
{
return ($number * $number * $number);
}
$nums = [1, 2, 3, 4, 5];
$cubed = array_map('cube', $nums);
Example 2: php array map
$func = function cube($n) {
return ($n * $n * $n);
}
$a = [1, 2, 3, 4, 5];
$b = array_map( $func, $a );
// Outputs: Array (
// [0] => 2
// [1] => 4
// [2] => 6
// [3] => 8
// [4] => 10
// )