PHP array_walk_recursive()関数
例
ユーザー定義関数で各配列要素を実行します。
<?php
function myfunction($value,$key)
{
echo "The key $key has the value $value<br>";
}
$a1=array("a"=>"red","b"=>"green");
$a2=array($a1,"1"=>"blue","2"=>"yellow");
array_walk_recursive($a2,"myfunction");
?>
定義と使用法
array_walk_recursive()関数は、ユーザー定義関数の各配列要素を実行します。配列のキーと値は、関数のパラメーターです。この関数とarray_walk() 関数の違いは、この関数を使用すると、より深い配列(配列内の配列)を操作できることです。
構文
array_walk_recursive(array, myfunction, parameter...)
パラメータ値
Parameter | Description |
---|---|
array | Required. Specifying an array |
myfunction | Required. The name of the user-defined function |
parameter,... | Optional. Specifies a parameter to the user-defined function. You can assign one parameter to the function, or as many as you like. |
技術的な詳細
戻り値: | 成功した場合はTRUEを返し、失敗した場合はFALSEを返します |
---|---|
PHPバージョン: | 5歳以上 |
❮PHP配列リファレンス