array_walk_recursive() 对数组中的每个成员递归地应用用户函数

 

实例

对数组中的每个元素应用用户自定义函数:

<?php
function myfunction($value,$key)
{
echo "The key $key has the value $value<br>";
}
$a1=array("a"=>"red","b"=>"green");
$a2=array($a1,"1"=>"blue","2"=>"yellow");
array_walk_recursive($a2,"myfunction");
?>

输出
The key a has the value red
The key b has the value green
The key 1 has the value blue
The key 2 has the value yellow

定义和用法

array_walk_recursive() 函数对数组中的每个元素应用用户自定义函数。在函数中,数组的键名和键值是参数。该函数与 array_walk() 函数的不同在于可以操作更深的数组(一个数组中包含另一个数组)。


语法

array_walk_recursive(array,myfunction,parameter...)

参数描述
array必需。规定数组。
myfunction必需。用户自定义函数的名称。
parameter,...可选。规定用户自定义函数的参数,您可以为函数设置一个或多个参数。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值