Описание тега array-map
PHP's array_map() function accepts Callback function to run for each element in each array and an array to run through the callback function.
PHP's array_map()
function accepts Callback function to run for each element in each array and an array to run through the callback function. It returns an array containing all the elements of arr1 after applying the callback function to each one.
array array_map ( callable $callback , array $array1 [, array $... ] )
array_map()
— Applies the callback to the elements of the given arrays
Example:
function cube($n)
{
return($n * $n * $n);
}
$a = array(1, 2, 3, 4, 5);
$b = array_map("cube", $a);
print_r($b);
Output:
Array
(
[0] => 1
[1] => 8
[2] => 27
[3] => 64
[4] => 125
)