php里array_work用法实例分析

 2025-01-16  阅读 597  评论 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用法实例分析-第1张-php-LS'Blog-保定PHP程序员老宋个人博客

// 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教程

评论列表:

  •   xixi2
     发布于 2025-01-15 01:50:52回复该评论
  • 哈哈哈不错!
  •   xiaoming22
     发布于 2025-01-15 07:50:52回复该评论
  • 哈哈哈不错!
  •   rick.li
     发布于 2025-01-15 19:50:52回复该评论
  • 哈哈哈不错!
  •   weihang
     发布于 2025-01-16 01:50:52回复该评论
  • 支持一下!
  •   echo111
     发布于 2025-01-16 07:50:52回复该评论
  • 哈哈哈不错!
  •   hahaha1
     发布于 2025-01-16 13:50:52回复该评论
  • 谢谢分享!
显示更多评论

发表评论:

管理员

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

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

页面耗时0.0295秒, 内存占用2.05 MB, 访问数据库32次

冀ICP备19034377号