← All built-ins / array_map()
array_map()
array_map(...$args): mixed
Parameters
| Name | Type | Description |
|---|---|---|
| $fn | closure | transform fn($value[, $value2, …]) |
| $a | array | array to transform |
| $... | array | more 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