← All built-ins / array_map()

array_map()

array_map(...$args): mixed

Parameters

NameTypeDescription
$fnclosuretransform fn($value[, $value2, …])
$aarrayarray to transform
$...arraymore arrays — one value per array is passed to $fnoptional

Return value

New array with the transformed values.

Example

$b = array_map(fn($x) => $x * $x, [1, 2, 3, 4]);
echo implode(",", $b);
1,4,9,16

See also

array_filter()array_reduce()array_walk()