Arrayadapter PHP array_walk Array functions

Source: Internet
Author: User
Copy CodeThe code is as follows:


/* Function Array_walk (): Single array callback function---Apply user function to each member of the arrays
* 1, Syntax: bool Array_walk (array &array, callback funcname [, Mixed $userdata])
* 2, Description: Returns TRUE if successful, failure returns FALSE
* 3, Note:
* 3.1, $funcname is the user-defined callback function, accepts 2 parameters, the first parameter is an array $arr The value of Ay, the second argument is the key name of the
* array $array, and if the third argument $userdata is supplied, it is passed to the callback function as the third argument $funcname
* 3.2, using a callback function to directly change the values of each cell of the array, However, changing the individual key names is not valid for
* 3.3, and the function is not affected by array pointers within the arrays. Array_walk () traverses the entire array regardless of the position of the pointer
*
* 3.4, the user should not change the array itself in the callback function, such as Add/delete unit, unset unit, etc., if the Array_walk ()
* Function array changes, The behavior of this function is undefined and not expected.
*/
$words =array ("l" = "lemon", "O" and "Orange", "B" and "banana", "a" and "Apple");
//Define a callback function, output array element
function Words_print ($value, $key, $prefix) {
echo "$prefix: $key + = $value
\ n";
}
//define a callback function to directly change the value of the element
function Words_alter (& $value, $key) {
$value =ucfirst ($value);
$key =strtoupper (key);
}
//Output element value
Array_walk ($words, ' words_print ', ' words ');
//Change the value of the element
Array_walk ($words, ' words_alter ');
Echo



echo "
";


The results are as follows:

The above describes the Arrayadapter PHP array_walk array functions, including the arrayadapter aspects of the content, I hope to be interested in PHP tutorial friends 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.