当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > array_walk_recursive() 函数

PHP
WINDOWS下安装MySQL
PHP 制作 网站/服务器 监视脚本
用PHP和CSS制作活动按钮
PHP 单件模式
PHP MVC模式,类封装以及HACK
PHP 中使用正则表达式
PHP 防止 SQL 注入攻击
PHP 跨站点脚本攻击
PHP 防止用户操纵 GET 变量
PHP 防止远程表单提交

PHP 中的 array_walk_recursive() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 459 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The array_walk_recursive() function runs each array element in a user-made function. The array's keys and values are parameters in the function. The difference between this function and the array_walk() function is that with this function you can work with deeper arrays (an array inside an array). Returns True or False
array_walk()函数将一个数组中的元素应用于用户自定义函数中;该数组中的键和值作为用户自定义函数中的参数。该函数与array_walk()函数的不同点在于:使用array_walk_recursive()函数,你可以使用嵌套的数组[deeper arrays](即:数组中的数组)。

Syntax
语法

array_walk_recursive(array,function,parameter)

Parameter参数 Description描述
array Required. Specifying an array
必要参数。指定一个数组
function Required. The name of the user-made function
必要参数。指定用户自定义函数的名称
parameter Optional. Specifies a parameter to the user-made function
可选参数。为用户自定义函数指定一个参数


Tips and Notes
提示和注意点

Tip: You can assign one parameter to the function, or as many as you like.
提示:你可以向函数中指定一个或多个参数。


Example
案例

<?php
function myfunction($value,$key)
{
echo "The key $key has the value $value<br />";
}
$a1=array("a"=>"Cat","b"=>"Dog");
$a2=array($a1,"1"=>"Bird","2"=>"Horse");
array_walk_recursive($a2,"myfunction");
?>

The output of the code above will be:
上述代码将输出下面的结果:

The key a has the value Cat
The key b has the value Dog
The key 1 has the value Bird
The key 2 has the value Horse

评论 (0) All

登陆 | 还没注册?