Array_map () calls the callback function to a given array unit. [function] This function returns an array, this array contains all units in array1 that have passed the callback function. The number of parameters received by the callback function should be passed to array_m... SyntaxHighlighter.
Array_map () calls the callback function to a given array unit.
[Function]
This function returns an array,
This array contains all units in array1 that have passed the callback function.
The number of parameters received by the callback function should be the same as the number of arrays passed to the array_map () function.
Scope of use]
Php4> 4.0.6, php5.
[Use]
Array array_map (callback, array arr1 [, array...])
Callback/required/provided by the user as a standard callback function
Arr1/required/comparative array
Array.../optional/array for comparison
[Example]
[Php]
// Define the callback function
Function cube ($ n ){
Return ($ n * $ n );
}
$ A = array (1, 2, 3, 4, 5 );
$ B = array_map ("cube", $ );
Var_dump ($ B );
/*
Array (5 ){
[0] =>
Int (1)
[1] =>
Int (8)
[2] =>
Int (27)
[3] =>
Int (64)
[4] =>
Int (125)
}
*/
Taken from zuodefeng's note