PHP array_walk () array function _php Tutorial

Source: Internet
Author: User
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 ...

  • 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.