Master programming syntax, solve interactive challenges & run live code in Syntaxis Explore Arena →
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): array

Parameters

NameTypeDescription
callbackcallable|nullCallback function to run for each element.
arrayarrayAn 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.