array_map in php example
The array_map() function iterate through array and send and get back the new value from the user defined function.
Syntax:
array_map(“user-defined-function-names”,$array_name);
Program1: array_map1.php
<?php function naveentokumar($name) //user defined function to check array value is Naveen or not. { if($name !="naveen") { return "kumar"; } return $name; } $myarr=array("diva","salai","hems","bala","naveen","hussain"); print_r(array_map("naveentokumar",$myarr)); ?>
Output:
Program2: array_map2.php
<?php $letter=array("N","A","V","E"); $value=array("5","1","6","5"); print_r(array_map(null,$letter,$value)); ?>
Output:
Thanks for reading this post……………..!!!