"apple","b"=>"banana","c"=>"orange");function test_alter(&$item1,$key,$prefix){$item1 = "$prefix:$item1";}function test_print($item2,$key){echo "$key.$item2\n";}echo "Before.....\n";array_walk($fruits, 'test_print')"> 跳转到主内容
websoft网络软件专家 - 深耕网络技术,打造实用软件!

关于array_walk的有关问题

关于array_walk的问题php
"lemon","a"=>"apple","b"=>"banana","c"=>"orange");function test_alter(&$item1,$key,$prefix){$item1 = "$prefix:$item1";}function test_print($item2,$key){echo "$key.$item2\n";}echo "Before.....\n";array_walk($fruits, 'test_print');array_walk($fruits, 'test_alter','fruit');echo "...and after:\n";array_walk($fruits,'test_print');?>关于这段代码的 最后几行的遍历 表示理解不能  求大大们帮我细细的分析一下 让我理解~

分享到:

Baidu Button BEGIN更多Baidu Button END------解决方案--------------------array_walk($fruits, 'test_print');用回调函数 test_print 打印数组 $fruits 的每个成员相当于foreach($fruits as $k=>$v) test_print($v, $k);array_walk($fruits, 'test_alter','fruit');用回调函数 test_alter 给数组 $fruits 的每个成员的值的前面加上字符串 'fruit.'相当于foreach($fruits as $k=>$v) $fruits[$k] = test_alter($v, 'fruit');

相关文章