This function applies any native PHP function or user defined function to each element of the array. This can be applied to multiple arrays.
array_map(my_function, array1,array2......);
my_function : Required , user defined or native PHP functions array1 : Required , All elements has to pass through the function array2 : Optional , All elements has to pass through the function
Output is an array ( return value of function )
Here number of arrays must be equal to number of parameters passed to array_map function.
We will try some examples.
We need to reduce the value of all the elements of an array by half. Here we can easily use array_map function and change.
$a=array(15,12,13,25,27,36,18);
function array_adj($n){
return($n/2);
}
$a=array_map("array_adj",$a);
print_r($a);
We can use PHP native function also. Here is an example where we used string function strtoupper to change all lower case elements to upper case elements of an array.