array_walk(array &$array, callable $callback [, mixed $userdata = NULL ]): bool
$array = [1, 2, 3, 4, 5];
function square(&$value)
{
$value = $value * $value;
}
array_walk($array, 'square');
print_r($array); // 输出 [1, 4, 9, 16, 25]
$array = [1, 2, 3, 4, 5];
array_walk($array, function(&$value) {
$value = $value * $value;
});
print_r($array); // 输出 [1, 4, 9, 16, 25]
$array = [1, 2, 3, 4, 5];
$total = 0;
function sum(&$value, $key, $userdata)
{
$value = $value + $userdata;
}
array_walk($array, 'sum', 10);
print_r($array); // 输出 [11, 12, 13, 14, 15]
本文为翻滚的胖子原创文章,转载无需和我联系,但请注明来自猿教程iskeys.com