Array in php

Source: Internet
Author: User
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"
}


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.