PHPArrayarray_map

Applies the callback to the elements of the given array.

Syntax

array_map(?callable $callback, array $array): array

Example

Enter values below to update the example in real time.

nums
evens
array_filter
fn
squared
array_map
array_values
print_r
$nums = [1, 2, 3, 4, 5, 6];
$evens = array_filter($nums, fn($n) => $n % 2 === 0);
$squared = array_map(fn($n) => $n ** 2, array_values($evens));
print_r($squared); // [4, 16, 36]