PHP - array_walk() 函式



語法

array_walk ( $array, $funcname [, $parameter] );

定義和用法

此函式返回一個數組,其中包含 array1 中所有存在於所有引數 array2、array3 中的值。

引數

序號 引數及描述
1

array(必需)

它指定一個數組。

2

funcname(必需)

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

3

parameter(可選)

它指定使用者自定義函式的引數。

示例

嘗試以下示例 -

<?php
   function call_back_function($value,$key) {
      echo "The key $key has the value $value \n";
   }
   $input = array("a"=>"green", "b"=>"brown", "c"=>"blue", "red");
   
   array_walk($input,"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 0 has the value red
php_function_reference.htm
廣告