Array_walk: array_walk () returns a Boolean value. If the callback function needs to directly act on the array, specify the first parameter of the callback function as a reference. In this way, any change to these units will also change the original array itself. This function can get both the key and value of the array. Array_map: array_map () returns an array.
Array_walk: array_walk () returns a Boolean value. If the callback function needs to directly act on the array, specify the first parameter of the callback function as a reference. In this way, any change to these units will also change the original array itself. This function can get both the key and value of the array. Array_map: array_map () returns an array.
Array_walk:
Array_walk () returns a Boolean value. If the callback function needs to act directly on the value in the array, the first parameter of the callback function is specified as a reference. In this way, any change to these units will also change the original array itself. This function can get both the key and value of the array.
Array_map:
Array_map () returns an array that contains all the elements in arr1 that have passed the callback function. The number of parameters accepted by callback should be the same as the number of arrays passed to the array_map () function.
To put it simply, the callback function will have a final impact on each value in the array and will be reflected in the returned value of calling array_map.
This function can operate on multiple arrays at the same time. And finally merged into an array (each array is parallel to it in the same two-dimensional array according to the subscript ).
Array_filter:
This function is specially used for elements in the past array. Simply put, it is used to filter the values judged by the callback function in the array and return the processed array through the array_filter () function.
Therefore, we can perform array preprocessing on THE array_walk and array_map tables. The most common operation is the trim operation on each array value. The following is the author's sample code:
| The Code is as follows: |
|
|
$ Tmp = array ('aaaa BBBB cccccccc', 'aaaa bbbb C', 'dddddd eeeee ');
Function array_walk_func (& $ v, $ k ){
$ V = trim ($ v );
}
Array_walk ($ tmp, 'array _ Functions _func ');
Var_dump ($ tmp );
Function array_map_func ($ v ){
Return trim ($ v );
}
$ Ret = array_map ('array _ map_func ', $ tmp );
Var_dump ($ ret );
Output result:
Array (3 ){
[0] =>
String (14) "aaaa bbbb cccc"
[1] =>
String (11) "aaaa bbbb c"
[2] =>
String (13) "dddddd eeeeee"
}
Array (3 ){
[0] =>
String (14) "aaaa bbbb cccc"
[1] =>
String (11) "aaaa bbbb c"
[2] =>
String (13) "dddddd eeeeee"
}
|