Applies a function to an array.
The array_walk() function applies the specified function to every element in an array. The value and key of the element being processed are always passed to the function. If the optional argument parameter is passed to array_walk(), it is also passed to the function.
// prints an element
function myPrint($value)
{
print "$value ";
}
// multiplies an element with the specified factor
function multiply(&$value, $key, $factor)
{
$value *= $factor;
}
$array1 = array(1, 2, 3);
// multiply the element by three
array_walk($array1, "multiply", 3);
// print the elements
array_walk($array1, "myPrint");
?>
3 6 9
Two functions are used together with array_walk() to multiply all the elements in an array and print the result.