Arrays are a very important part of PHP programming. This article describes the use of the array function Array_map () in PHP to effect the callback function on a given array cell. Specifically as follows:
Array Array_map (callable $callback, array $arr 1 [, Array $ ...])
Array_map () returns an array that contains the cells of all cells in the arr1 after the callback function.
The number of arguments accepted by callback should be consistent with the number of arrays passed to the Array_map () function.
The sample program is as follows:
function Fun ($n)
{return
$n * $n * $n;
}
$a = Array (1, 2, 3, 4, 5);
$b = Array_map (' fun ', $a); /* Each array unit is three Times Square operation, returns the array
/Print_r ($b);
The output results are:
Array
(
[0] => 1
[1] => 8
[2] =>
[3] =>
[4] =>
)
In addition, the Array_map () function has the following several uses:
Array_map (' unlink ', glob (' *.txt '));/* Glob returns an array of "filename. txt" and deletes each file
/array_map (' unlink ', glob (' *.* '));
Array_map (' unlink ', glob (' * '));
If you do not use Array_map (), each unit of an array can be manipulated and then properly assembled.
More application readers can dig according to the specific project requirements.