PHP - array_walk_recursive() 函式



語法

array_walk_recursive( $array, $funcname [,$parameter])

定義和用法

array_walk_recursive() 函式將使用者自定義函式應用於陣列中的每個元素。陣列的鍵和值都是函式的引數。

引數

序號 引數及描述
1

array (必需)

指定一個數組。

2

funcname (必需)

使用者自定義函式的名稱。

3

引數 (可選)

指定傳遞給使用者自定義函式的引數。

示例

嘗試以下示例:

<?php
   function call_back_function($value,$key) {
      echo "The key $key has the value $value \n";
   }
   
   $input1 = array("a"=>"green", "b"=>"brown", "c"=>"blue" );
   $input2 = array($input1, "d"=>"yellow", "e"=>"black");
   
   array_walk_recursive($input2,"call_back_function");
?> 

這將產生以下結果:

The key a has the value green
The key b has the value brown
The key c has the value blue
The key d has the value yellow
The key e has the value black
php_function_reference.htm
廣告