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

77 阅读1分钟

array_walk_recursive() - 语法

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

函数的作用是:运行用户自定义函数中的每个数组元素。数组的键和值是函数中的参数。

Sr.No Parameter & Description
1

array(必需)

它指定一个数组。

2

funcname(必需)

用户自定义函数的名称。

3

parameter(可选)

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

array_walk_recursive() - 示例

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

参考链接

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