php里array_work用法实例分析_php技巧

WBOY
發布: 2016-05-16 20:10:52
原創
1011 人瀏覽過

本文实例讲述了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
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!