码迷,mamicode.com
首页 > Web开发 > 详细

PHP array_walk() 函数

时间:2018-04-06 12:24:21      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:gpo   wal   引用   red   key   元素   pre   参数   run   

 

定义和用法

array_walk() 函数对数组中的每个元素应用用户自定义函数。在函数中,数组的键名和键值是参数。

<?php
function myfunction($value,$key,$p)
{
echo "$key $p $value<br>";
}
$a=array("a"=>"red","b"=>"green","c"=>"blue");
array_walk($a,"myfunction","has the value");
?>

结果

a has the value red
b has the value green
c has the value blue

其实传参,数组哪里($value)可以加个&,那就代表引用(指针),把原始数组也更改了.

 

<?php
function myfunction(&$value,$key,$p)
{
echo "$key $p $value<br>";
}
$a=array("a"=>"red","b"=>"green","c"=>"blue");
array_walk($a,"myfunction","has the value");
?>

 

 

参考:http://www.runoob.com/php/func-array-walk.html

PHP array_walk() 函数

标签:gpo   wal   引用   red   key   元素   pre   参数   run   

原文地址:https://www.cnblogs.com/fps2tao/p/8727122.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!