Php Array Mapping Function

What is array_map() Function?


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.



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 :

function funct1($d)
if ($d==="Cherry")
return "Red";
return $d;
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".

PHP Topics

Ask Questions

Ask Question