This article mainly introduces the usage of PHP array function array_walk, and analyzes the usage skills of array_walk to call user functions for each member of the array. Friends who need it can refer to it
The details are as follows:
$words=array("l"=>"lemon","o"=>"orange","b"=>"banana","a"=>"apple"); //定义一个回调函数,输出数组元素 function words_print($value,$key,$prefix){ echo "$prefix:$key=>$value<br>\n"; } //定义一个回调函数直接改变元素的值 function words_alter(&$value,$key){ $value=ucfirst($value); $key=strtoupper(key); } //输出元素的值 array_walk($words,'words_print','words'); //改变元素的值 array_walk($words,'words_alter'); echo "<pre class="brush:php;toolbar:false">"; print_r($words); echo "";
Example of class internal calls:
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 '';
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
phpDetailed explanation of WeChat development access example
PHP MySQL implementation fuzzy Query employee information function
PHP MySQL implements the function of jumping to the specified page by entering the page number
The above is the detailed content of PHP array function array_walk usage and examples. For more information, please follow other related articles on the PHP Chinese website!