Reference / PHP
array_map()
Applies the callback to the elements of the given arrays and returns an array containing the results.
Syntax
array_map(?callable $callback, array $array, array ...$arrays): arrayParameters
| Name | Type | Description |
|---|---|---|
| callback | callable|null | Callback function to run for each element. |
| array | array | An array to run through the callback function. |
Examples
Doubling numbers
$nums = [1, 2, 3, 4];
$doubled = array_map(fn($n) => $n * 2, $nums);
print_r($doubled); // [2, 4, 6, 8]Preserves integer index order but re-indexes non-string keys from 0.