array_walk -- Apply a user function to every member of an array.


int array_walk(array arr, string func);

Applies the function named by func to each element of arr. The elements are passed as the first argument of func; if func requires more than one argument, a warning will be generated each time array_walk() calls func. These warnings may be suppressed by prepending the '@' sign to the array_walk() call, or by using error_reporting().

Note: func will actually be working with the elements of arr, so any changes made to those elements will be made in the array itself.

Example 1. array_walk() example

$fruits = array("d"=>"lemon","a"=>"orange","b"=>"banana","c"=>"apple");

function test_alter( $item1 ) {
   $item1 = 'bogus';

function test_print( $item2 ) {
   echo "$item2<br>\n";

array_walk( $fruits, 'test_print' );
array_walk( $fruits, 'test_alter' );
array_walk( $fruits, 'test_print' );

See also each() and list().