php里array_work用法实例分析

yipeiwu_com6年前PHP代码库

本文实例讲述了php里array_work用法。分享给大家供大家参考。具体如下:

// the test array 
$array = array(
  'php', 'arrays', 'are', 'cool'  
);
// some variable for testing:
$some_var = 'NEW';
// the function that get's called for each entry
function format_array_values(&$item, $key, $some_var) {
  $item = $some_var . ": $item (KEY: $key)<br/>";
}
// "walk" trough each array item and call the function:
// "format_array_values"
array_walk($array, 'format_array_values', $some_var);
// print the result:
print_r($array);
/*
The output will be:
Array
(
  [0] => NEW: php (KEY: 0)<br/>
  [1] => NEW: arrays (KEY: 1)<br/>
  [2] => NEW: are (KEY: 2)<br/>
  [3] => NEW: cool (KEY: 3)<br/>
)
*/

希望本文所述对大家的php程序设计有所帮助。

相关文章

PHP 图像尺寸调整代码

复制代码 代码如下: /********************** *@filename - path to the image *@tmpname - temporary path...

PHP单元测试利器 PHPUNIT深入用法(三)第1/2页

PHP单元测试利器 PHPUNIT深入用法(三)第1/2页

在本文中,笔者将为大家介绍phpunit中的两个高级概念和用法,尽管它不一定在你的日常单元测试中都用到,但理解和学会它们的用法对学习phpunit还是十分重要的。   Phpunit中...

php 定界符格式引起的错误

php 定界符格式引起的错误

错误代码:Parse error: syntax error, unexpected $end in H:\wamp\www\testing\test\2.1.4.php on line...

在PHP里得到前天和昨天的日期的代码

前天去面试的时候也是这样,不过我当时记不起来了.就记得MYSQL里面的date_sub(now(),'interval 1 day');date('Y/m/d&nbs...

深入解析php中的foreach函数

Foreach 函数(PHP4/PHP5)foreach 语法结构提供了遍历数组的简单方式。foreach 仅能够应用于数组和对象,如果尝试应用于其他数据类型的变量,或者未初始化的变量将...