Introduction: This is a detailed page of the PHP function-Array Function array_walk (). It introduces PHP, related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 340726 'scrolling = 'no'> 1/* function array_walk (): single array callback function --- apply user functions to each member in the array
2*1. Syntax: bool array_walk (array & array, callback funcname [, mixed $ userdata])
3*2. Description: True is returned if the call succeeds, and false is returned if the call fails.
4*3. Notes:
5*3.1 and $ funcname are user-defined callback functions. Two parameters are accepted. The first parameter is the value of array $ array, and the second parameter is
6 * array $ array key name. If the third parameter $ userdata is provided, it will be passed as the third parameter to the callback function $ funcname
7*3.2 using the callback function, you can directly change the values of each cell in the array, but changing the key names is invalid.
8*3.3. This function is not affected by array pointers in the array. Array_walk () traverses the entire array regardless of the pointer.
Location of 9 *
10*3.4. The user should not change the array itself in the callback function, such as adding/deleting units and unset units. If array_walk ()
If the array of the 11 * function is changed, the behavior of the function is undefined and unpredictable.
12 */
13 $ words = array ("L" => "Lemon", "O" => "orange", "B" => "banana ", "A" => "apple ");
14 // define a callback function to output array elements
15 function words_print ($ value, $ key, $ prefix ){
16 echo "$ Prefix: $ key =>$ value <br> \ n ";
17}
18 // define a callback function to directly change the element value
19 function words_alter (& $ value, $ key ){
20 $ value = ucfirst ($ value );
21 $ key = strtoupper (key );
22}
23 // value of the output Element
24 array_walk ($ words, 'words _ print', 'word ');
25 // change the element value
26 array_walk ($ words, 'words _ alter ');
27 echo "<PRE> ";
28 print_r ($ words );
29 echo "</PRE>"; the running effect is as follows:
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/340726.html pageno: 7.