无涯教程-PHP - array_walk()函数

75 阅读1分钟

array_walk() - 语法

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

此函数返回一个数组,其中包含所有参数array2、array3中存在的array1的所有值。

Sr.No Parameter & Description
1

array(必需)

它指定一个数组。

2

funcname(必需)

用户自定义函数的名称。

3

parameter(可选)

它为用户自定义函数指定一个参数。

array_walk() - 示例

<?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

参考链接

www.learnfk.com/php/php-fun…