PHP array_walk() 函数
定义和用法
array_walk() 函数对数组中的每个元素应用用户自定义函数。在函数中,数组的键名和键值是参数。
<?php function 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 red
b has the value green
c has the value blue
其实传参,数组哪里($value)可以加个&,那就代表引用(指针),把原始数组也更改了.
<?php function 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