PHP Array function Array_walk Usage example, array array_walk
This article describes the use of PHP array function array_walk. Share to everyone for your reference, as follows:
$words =array ("l" = "lemon", "o" = "Orange", "b" = "banana", "a" and "apple");//define a callback function, output array element function words _print ($value, $key, $prefix) { echo ' $prefix: $key + $value
\ n ";} Defines a callback function that directly alters the value of the 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 the element Array_walk ($words, ' words_alter '); echo "";p Rint_r ($words); echo"
";
Class Internal invocation Example:
Class Arraywalk { /** * Properties: * /var $body _chunk = Array (' 0 ' = ' dewen ', ' 1 ' = ' PHP ', 2=> ' Linux '); //VARIABLE METHODS ////////////////////////////////// function Arraywalk () { } function Func_1 () { print_r ($this->body_chunk); Array_walk ($this->body_chunk, Array ($this, ' spellstrtolower ')); Print_r ($this->body_chunk); } Function Spellstrtolower (& $str) { $str = Strtolower ($STR); }} $obj = new Arraywalk (); Echo ''; $obj->func_1 (); Echo '
';
Add: small make up here to recommend a site of the PHP format beautification of the layout tools to help you in the future of PHP programming code layout:
PHP Code online format Beautification tool:
Http://tools.jb51.net/code/phpformat
In addition, because PHP is a C language style, the following tool can also be used to implement the PHP code format:
C Language Style/html/css/json code formatting beautification tool:
Http://tools.jb51.net/code/ccode_html_css_json
More about PHP related content readers can view this site topic: "PHP array" operation Skills Daquan, "PHP Sorting algorithm Summary", "PHP common traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", " PHP Math Skills Summary, "PHP Regular Expression Usage summary", "PHP Operations and Operator Usage Summary", "PHP string Usage Summary" and "PHP common database Operation Skills Summary"
I hope this article is helpful to you in PHP programming.
http://www.bkjia.com/PHPjc/1133078.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133078.html techarticle php Array Function Array_walk Usage example, array Array_walk This example describes the use of PHP array functions array_walk. Share to everyone for your reference, as follows: $words =array ("L" ...