array_map() function in php
0 2707
array_map() function of PHP is used to alter all items of one or more arrays with the help of a user define function means it apply user define conditions to each items of array and returns new array. It is an inbuilt function of PHP.
Syntax:
array_map (user_define_function,$arr1,$arr2,.....,$arrN);
Here
user_define_function is a callback function or user define function and $aar1,$arr2,$arrN are PHP arrays.
Example:
<?php // this example add 10 to each elements of array $arr1 function add_value($x) { return ($x + 10); } $arr1 = array(2,3,4,5,6,7,8,9); $result=array_map("add_value",$arr1); echo "<pre>"; print_r($result); ?>
Output:
Share:
Comments
Waiting for your comments