Welcome to Findnerd. Today we are going to discuss the array function that is array_map which takes two main arguments one for callback function and other arguments
are in form of arrays. It will return the array according to callback function. array_map function passes the arrays to the callback function. Please have a look.
<?php
$pra = array(243,244,225,146);
function productOpt($pra_num){
return ($pra_num*$pra_num);
}
$final_arr = array_map("productOpt",$pra);
?>
It will return the array according to callback function operation. array_map can also take multiple arrays. Please have a look.
<?php
$arr1 = array(243,244,225,146);
$arr2 = array(143,444,525,143);
function CompareOpt($arr1,$arr2){
if($arr1>$arr2)
return ($arr1);
else
return ($arr2);
}
$final_arr = array_map("CompareOpt",$arr1,$arr2);
?>
In above example we created two different arrays and comparing the elements from both arrays.
0 Comment(s)