Php Array Mapping Function
What is array_map() Function?
Explanation
The "array_map()" function sends each value of an array to a function, then returns an array with new value that are modified inside the function.
Syntax:
array_map(function,array1,array2,array3)
In the above syntax the "array1" is an mandatory field, "array2", "array3" are optional, "function" is also a mandatory field, to which all the values of "array1" is send to.
Example :
<?php
function funct1($d)
{
if ($d==="Cherry")
{
return "Red";
}
return $d;
}
$a=array("Guava","Cherry","Orange");
print_r(array_map("funct1",$a));
?>
Result :
Array ( [0] => Guava [1] => Red [2] => Orange )
In the above example each value of the array "$a" is send to the function "funct1", where the value "Cherry" is checked for,if true, then returns the value "Red".