Array, walk: Xin Xing analyzes the relationship and difference between array_walk and array_map: Let's take a look at the specific usage of the two functions. The first is array_walk. the code is as follows: int41 for the specific use of these two functions, let's take a look at it first, the first is array_walk, the code is as follows:
The output content is as follows:array (size=5) 0 => int 4 1 => int 16 2 => int 25 3 => int 36 4 => int 49
Here is an example of array_map: The output content is as follows:array (size=4) 0 => int 10 1 => int 18 2 => int 28 3 => int 40
We can find that these two functions can be implemented for traversing arrays, but generally they have different focuses:
(1) array_map can traverse n arrays at the same time, while array_walk usually traverses one.
(2) the returned value of array_map must be a new array. However, array_walk is usually unnecessary because it is usually used to change the original data.
(3) array_map usually has a data function. However, it is not recommended to delete or add data in array_walk, but to modify the value.
Of course, they can implement the same functions in some cases. they are not distinct, but have some intersection.
The above introduces the connection and difference between Xin Xing's analysis of array_walk and array_map, including array and walk content, and hopes to help friends who are interested in PHP tutorials.