This article mainly introduces the PHP array function Array_walk usage, analyzes the use of the user function of each member in the Array_walk log set, the need for friends can refer to the following
Specific 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 <br>\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 "<pre>"; Print_r ($words); echo "</pre>";
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 ' <PRE> '; $obj->func_1 (); Echo ' </PRE> ';
Summary: The above is the entire content of this article, I hope to be able to help you learn.