Sinsing analysis of the relations and differences between Array_walk and Array_map array Walk class array walk trim array Walk anonymous letter

Source: Internet
Author: User
for the specific use of these two functions, let's take a look at it first, Array_walk, the code is as follows:

 Its output reads as follows:

Array (size=5)  0 + int 4  1 = int  2 = int 3  = int-  4 = int 49
And for Array_map, let's take an example:

  Its output reads as follows:

Array (size=4)  0 = int  1 = int  2 = int  3 = int 40

We can see that both functions can be implemented for things like traversing an array, but in general, they focus differently:

(1) Array_map can traverse n arrays at the same time, while Array_walk is usually traversing one.

(2) Array_map must have a return value because its return value needs to form a new array. But Array_walk is usually not necessary because its usual use is to change the original data.

(3) Array_map usually have a function of the data, but Array_walk does not recommend deleting and adding the data, it is recommended to modify the value only.

Of course, they can achieve the same function in some cases, they are not distinct, but have a certain intersection.

The above describes the Sinsing analysis of Array_walk and array_map of the relationship and differences, including the array,walk aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.