Array_walk:
Array_walk () returns a Boolean value that is specified as a reference to the first parameter of the callback function if the callback function needs to act directly on the value in the array. Any changes to these units will also change the original array itself. This function can get both the key and value of the array at the same time.
Array_map:
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 simple point is that the callback function has a final effect on each value in the array, and is reflected in the return value of the call Array_map.
This function can operate on multiple arrays at the same time. And eventually merged into an array (each array is parallel to the subscript to the same two-dimensional array).
Array_filter:
This function is dedicated to the elements in the past array, simply by filtering the value of the callback function in the array and returning the processed array via the Array_filter () function.
So the analysis to this we can be yo on a array_walk and array_map to do array preprocessing, most commonly is the trim operation on each array value. The following is the author's sample code:
| The code is as follows |
Copy Code |
|
<?php
$tmp = Array (' AAAA bbbb CCCC ', ' aaaa bbbb c ', ' dddddd eeeeee ');
Function Array_walk_func (& $v, $k) {
$v = Trim ($v);
}
Array_walk ($tmp, ' array_walk_func ');
Var_dump ($tmp);
Function Array_map_func ($v) {
return trim ($v);
}
$ret = Array_map (' Array_map_func ', $tmp);
Var_dump ($ret);
Output:
Array (3) {
[0] =>
String (a) "AAAA bbbb CCCC"
[1] =>
; String (one) "AAAA bbbb C"
[2] =>
string dddddd eeeeee "
}
Array (3) {
[0] =& Gt
string "AAAA bbbb CCCC"
[1] =>
string (one) aaaa bbbb c
[2] =>
string "dddddd eeeeee"
} |