A PHP function that walks an array and applies a provided function on the array elements.
A PHP function that walks an array and applies a provided function on the array elements.
bool array_walk ( array &$array , callable $callback [, mixed $userdata = NULL ] )
Applies the user-defined callback function to each element of the array array. manual
array_walk()
is not affected by the internal array pointer of array. array_walk()
will walk through the entire array regardless of pointer position.
Example
$fruits = array("lemon", "orange", "banana", "apple");
function test_alter(&$item1, $key, $prefix){
$item1 = "$prefix: $item1";
}
array_walk($fruits, 'test_alter', 'fruit');
print_r($fruits);
Result
Array
(
[0] => fruit: lemon
[1] => fruit: orange
[2] => fruit: banana
[3] => fruit: apple
)