定義和用法
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
