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
广告

© . All rights reserved.