Copy CodeThe code is as follows:
/* Function Array_walk (): Single array callback function---Apply user function to each member in a logarithmic group
* 1, Syntax: bool Array_walk (array &array, callback funcname [, mixed $userdata])
* 2, Description: Returns TRUE if successful, failure returns FALSE
* 3. Precautions:
* 3.1, $funcname is the user's own definition of the callback function, accept 2 parameters, the first parameter is the value of the array $array, the second parameter is
* The key name of the array $array, if supplied with the third parameter $userdata, is passed as the third argument to the callback function $funcname
* 3.2, the callback function can be used to directly change the values of the elements of the array, but changing the individual key names is not valid
* 3.3, the function will not be affected by array pointers within an array. Array_walk () traverses the entire array regardless of the pointer
* The location
* 3.4, the user should not change the array itself in the callback function, such as Add/delete unit, unset unit, etc., if Array_walk ()
* The function's behavior is undefined and unpredictable because the array of functions has changed.
*/
$words =array ("l" = "lemon", "o" = "Orange", "B" and "banana", "a" and "Apple");
Defines a callback function that outputs an array of elements
function Words_print ($value, $key, $prefix) {
echo "$prefix: $key + $value
\ n ";
}
Define a callback function to directly change the value of an element
Function Words_alter (& $value, $key) {
$value =ucfirst ($value);
$key =strtoupper (key);
}
The value of the output element
Array_walk ($words, ' words_print ', ' words ');
Change the value of an element
Array_walk ($words, ' words_alter ');
echo "
echo "
";
The results are as follows:
http://www.bkjia.com/PHPjc/323852.html www.bkjia.com true http://www.bkjia.com/PHPjc/323852.html techarticle Copy the code code as follows:/* function Array_walk (): Single array callback---apply user function to each member of the logarithmic group * 1, Syntax: BOOL Array_walk (array gt; Lemon "," o "=" Oran ...