This article illustrates the use of PHP array function array_walk. Share to everyone for your reference, specific as follows:
$words =array ("L" => "Lemon", "O" => "Orange", "B" => "banana", "a" => "Apple");
Defines a callback function that outputs an array element
function Words_print ($value, $key, $prefix) {
echo $prefix: $key => $value <br>\n ";
}
//Define a callback function to directly change 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>";
Example of an internal call to a class:
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> ';
Add: Small knitting here recommend a site for the layout of the PHP format landscaping tools to help you in the future of PHP programming code layout:
PHP code online format Landscaping tools:
Http://tools.jb51.net/code/phpformat
In addition, because PHP belongs to the C language style, the following tool can also be used to format PHP code:
C Language Style/html/css/json code formatting landscaping Tools:
Http://tools.jb51.net/code/ccode_html_css_json
More about PHP Interested readers can view the site topics: "PHP array" Operation tips Daquan, "PHP Sorting algorithm Summary", "PHP common traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", " PHP Mathematical Calculation Skills Summary, "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP string (String) Usage summary" and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.