PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular

array_map

Tags: PHP 5.x PHP 7.x PHP 8.x

array_map — Applies the callback to the elements of the given arrays.

Description

array_map(
    ?callable $callback,
array $array,
array ...$arrays
): array
array_map() returns an array containing the results of applying the callback to the corresponding index of array (and arrays if more arrays are provided) used as arguments for the callback. The number of parameters that the callback function accepts should match the number of arrays passed to array_map(). Excess input arrays are ignored. An ArgumentCountError is thrown if an insufficient number of arguments is provided.

Parameters

callback
A callable to run for each element in each array.
null can be passed as a value to callback to perform a zip operation on multiple arrays. If only array is provided, array_map() will return the input array.
array
An array to run through the callback function.
arrays
Supplementary variable list of array arguments to run through the callback function.

Return Values

Returns an array containing the results of applying the callback function to the corresponding index of array (and arrays if more arrays are provided) used as arguments for the callback.
The returned array will preserve the keys of the array argument if and only if exactly one array is passed. If more than one array is passed, the returned array will have sequential integer keys.

array_map - New snippets