/*Function array_walk(): Single array callback function---for each member in the array Apply user function
* 1. Syntax: bool array_walk ( array &array, callback funcname [, mixed $userdata] )
* 2. Description: Return TRUE if successful, return FALSE if failed
* 3. Notes:
* 3.1. $funcname is a callback function defined by the user. It accepts 2 parameters. The first parameter is the value of the array $array, and the second parameter is the key name of the array $array. , if the third parameter $userdata is provided, it will be passed to the callback function $funcname as the third parameter
* 3.2. Using the callback function can directly change the value of each unit of the array, but changing each key name is invalid
* 3.3. This function will not be affected by the internal array pointer of array. array_walk() will traverse 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 adding/deleting cells, unset cells, etc., if array_walk()
* If the array it acts on changes, the behavior of this function is undefined and unpredictable.
*/
$words=array("l"=>"lemon","o"=>"orange","b"=>"banana","a"=>" apple");
//Define a callback function to output array elements
function words_print($value,$key,$prefix){
echo "$prefix:$key=>$value
}
//Define a callback function to directly change the value of the element
function words_alter(&$value,$key){
$value=ucfirst($value);
$key=strtoupper(key);
}
//Output the value of the element
array_walk($words,'words_print','words');
//Change the value of the element
array_walk($words,'words_alter');
echo "
"; <br>print_r($words); <br>echo "
";