2
Test array_walk() function : basic functionality - regular array
5
/* Prototype : 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
10
echo "*** Testing array_walk() : basic functionality ***\n";
13
$fruits = array("lemon", "orange", "banana", "apple");
15
/* Prototype : test_print(mixed $item, mixed $key)
16
* Parameters : item - item in key/item pair
17
* key - key in key/item pair
18
* Description : prints the array values with keys
20
function test_print($item, $key)
22
// dump the arguments to check that they are passed
24
var_dump($item); // value
25
var_dump($key); // key
26
echo "\n"; // new line to separate the output between each element
28
function with_userdata($item, $key, $user_data)
30
// dump the arguments to check that they are passed
32
var_dump($item); // value
33
var_dump($key); // key
34
var_dump($user_data); // user supplied data
35
echo "\n"; // new line to separate the output between each element
38
echo "-- Using array_walk() with default parameters to show array contents --\n";
39
var_dump( array_walk($fruits, 'test_print'));
41
echo "-- Using array_walk() with all parameters --\n";
42
var_dump( array_walk($fruits, 'with_userdata', "Added"));
47
*** Testing array_walk() : basic functionality ***
48
-- Using array_walk() with default parameters to show array contents --
62
-- Using array_walk() with all parameters --