php里array_work用法实例分析

 2025-01-16  阅读 313  评论 8  点赞 214

摘要:本文实例讲述了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

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

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程序设计有所帮助。


标签:phpphp教程

评论列表:

显示更多评论

发表评论:

管理员

承接各种程序开发,外贸网站代运营,外贸网站建设等项目
  • 内容2462
  • 积分67666
  • 金币90666

Copyright © 2024 LS'Blog-保定PHP程序员老宋个人博客 Inc. 保留所有权利。 Powered by LS'blog 3.0.3

页面耗时0.0276秒, 内存占用1.94 MB, 访问数据库31次

冀ICP备19034377号