定义和用法
array_walk() 函数对数组中的每个元素应用用户自定义函数。在函数中,数组的键名和键值是参数。
<?phpfunction myfunction($value,$key,$p){echo "$key $p $value<br>";}$a=array("a"=>"red","b"=>"green","c"=>"blue");array_walk($a,"myfunction","has the value");?>
结果
a has the value redb has the value greenc has the value blue
其实传参,数组哪里($value)可以加个&,那就代表引用(指针),把原始数组也更改了.
<?phpfunction myfunction(&$value,$key,$p){echo "$key $p $value<br>";}$a=array("a"=>"red","b"=>"green","c"=>"blue");array_walk($a,"myfunction","has the value");?>
参考:http://www.runoob.com/php/func-array-walk.html
PHP array_walk() 函数
原文地址:https://www.cnblogs.com/fps2tao/p/8727122.html