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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM