2 Test array_walk() function : usage variations - anonymous callback function
5 /* Prototype : proto bool array_walk(array $input, string $funcname [, mixed $userdata])
6 * Description: Apply a user function to every member of an array
7 * Source code: ext/standard/array.c
11 * Passing anonymous(run-time) callback function with following variations:
19 echo "*** Testing array_walk() : anonymous function as callback ***\n";
21 $input = array(2, 5, 10, 0);
23 echo "-- Anonymous function with one argument --\n";
24 var_dump( array_walk($input, function($value) { var_dump($value); echo "\n"; }));
26 echo "-- Anonymous function with two arguments --\n";
27 var_dump( array_walk($input, function($value, $key) { var_dump($key); var_dump($value); echo "\n"; }));
29 echo "-- Anonymous function with three arguments --\n";
30 var_dump( array_walk($input, function($value, $key, $user_data) { var_dump($key); var_dump($value); var_dump($user_data); echo "\n"; }, 10));
32 echo "-- Anonymous function with null argument --\n";
33 var_dump( array_walk( $input, function() { echo "1\n"; }));
37 *** Testing array_walk() : anonymous function as callback ***
38 -- Anonymous function with one argument --
48 -- Anonymous function with two arguments --
62 -- Anonymous function with three arguments --
80 -- Anonymous function with null argument --