Php array function array_walk usage example, array array_walk. Php array function array_walk usage example. array array_walk this article describes the usage of php array function array_walk. For your reference, see $ wordsarray (l php array function array_walk usage example, array array_walk
This article describes how to use the php array function array_walk. We will share this with you for your reference. The details are as follows:
$ Words = array ("l" => "lemon", "o" => "orange", "B" => "banana ", "a" => "apple"); // defines a callback function and outputs the function words_print ($ value, $ key, $ prefix) {echo "$ prefix: $ key => $ value
\ N ";}// define a callback function to directly change the value of the element function words_alter (& $ value, $ key) {$ value = ucfirst ($ value ); $ key = strtoupper (key);} // array_walk ($ words, 'Words _ print ', 'Word') of the output element '); // change the value of the element array_walk ($ words, 'Words _ alter '); echo"";print_r($words);echo "
";
Class internal call 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 '
';
Supplement: The editor recommends a php formatting and formatting typographical tool on this site to help you typeset code in future PHP programming:
Php code online formatting and beautification tools:
Http://tools.jb51.net/code/phpformat
In addition, because php belongs to the C language style, the following tool can also format php code:
C language style/HTML/CSS/json code formatting and beautification tools:
Http://tools.jb51.net/code/ccode_html_css_json