array_map
array_map
array_map
- It applies the callback function to the elements of the given arrays
Syntax:
array array_map ( mixed callback, array arr1 [, array arr2…])
It returns an array containing all the elements of arr1 after applying the callback function to each one. The number of parameters that the
callback function accepts should match the number of arrays passed to the array_map()
Example:
function powerof2($n) {
return pow(2,$n);
}
$input = array(0, 1, 2, 3, 4, 5);
$output = array_map(”powerof2″, $input);
print_r($output);
The result in the array $output is
Array
(
[0] => 1
[1] => 2
[2] => 4
[3] => 8
[4] => 16
[5] => 32
)
