/*Function array_map() function: multi-array callback function---apply the callback function to
* 1. Syntax: array array_map (callback callback, array arr1 [, array ...])
* 2. Description: Returns an array that contains all the cells in arr1
* unit after callback has been applied. The number of arguments accepted by callback should match the number of arrays passed to the array_map() function.
* 3. Notes:
* 3.1. When the multi-array callback function acts on an array, the key name of the original array will be retained, that is, the key name of the returned array is
* when applied to Define the key name of the array
* 3.2. When the multi-array return function operates on two or more arrays, their lengths must be consistent, and the
* key names of the original multiple arrays will be ignored and numbers will be assigned uniformly. Index as key name
*/
//Example of using a single array
$websites=array("g"=>"google","b"=>"baidu","y" =>"yahoo");
//Output the original array
echo "
"; <br>print_r($websites); <br>echo "
";
//Define a callback function for processing a single array
function change_value($value){
return ucfirst($value).".com";
}
$urls=array_map('change_value ',$websites);
echo "
"; <br>print_r($urls); <br>echo "
";
//Example of using multiple arrays
$arr1=array(1,3,5,7);
$arr2=array(2,4,6,8);
//Define a callback function for processing multiple arrays
function func1($a,$b){
return $a*$b;
}
$results=array_map('func1',$arr1,$arr2);
echo "Use callback After the function processes multiple arrays, the result returned:
";
echo "
"; <br>print_r($results); <br>echo "
";