PHP array_map() Function
PHP array_map() Function
The array_map() function in PHP is used to return an array containing the results of applying the user-defined callback function over the elements of one or more arrays.
Syntax
array_map ( callable $callback , array $array1 [, array $... ] )
Parameter
callable(required)- This parameter represents the callback function to run for each element in each array.
array1(required)- This parameter specifies the input array.
…(optional)- It represents more arrays to map with.
Return
This function returns an array containing the results of applying the user-defined callback function over the elements of one or more arrays.
Example 1
Output
Array ( [0] => 0 [1] => 1 [2] => 4 [3] => 9 [4] => 16 [5] => 25 )
Example 2
Output
Array ( [0] => 0 is an even number [1] => 1 is an odd number [2] => 2 is an even number [3] => 3 is an odd number [4] => 4 is an even number [5] => 5 is an odd number [6] => 6 is an even number )
Example 3
Output
Array ( [0] => 0 [1] => 1 [2] => 8 [3] => 27 [4] => 64 [5] => 125 [6] => 216 )
