Copy Code code as follows:
/* function Array_map () function: Most group callback functions---the function of a callback function to a cell of a given array
* 1, Syntax: Array Array_map (callback callback, array arr1 [, array ...])
* 2, Description: Returns an array that contains all the cells in the arr1 after the callback function
Cell The number of arguments accepted by callback should be consistent with the number of arrays passed to the Array_map () function.
* 3, the attention matters:
* 3.1, when most group callback functions act on an array, the key name of the original array is preserved, that is, the key name of the returned array is
* The key name that acts on the given array
* 3.2, most groups return to function in two or more arrays, their length to be consistent, and will ignore the original multiple array of
* Key Name, uniformly assigns the numeric index as the key name
*/
Examples of the use of a single array
$websites =array ("G" => "Google", "B" => "Baidu", "y" => "Yahoo");
Output original Array
echo "<pre>";
Print_r ($websites);
echo "</pre>";
Defines a callback function that is processed on a single array
function Change_value ($value) {
Return Ucfirst ($value). ". COM ";
}
$urls =array_map (' Change_value ', $websites);
echo "<pre>";
Print_r ($urls);
echo "</pre>";
Examples of using multiple arrays
$arr 1=array (1,3,5,7);
$arr 2=array (2,4,6,8);
Defines callback functions that are processed on multiple arrays
function func1 ($a, $b) {
return $a * $b;
}
$results =array_map (' func1 ', $arr 1, $arr 2);
echo "Returns the result:<br> after using a callback function to handle multiple arrays";
echo "<pre>";
Print_r ($results);
echo "</pre>";
The operation effect is as follows: