array_map

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
)

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.