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.