1--TEST--
2Test array_walk() function : basic functionality - regular array
3--FILE--
4<?php
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
8*/
9
10echo "*** Testing array_walk() : basic functionality ***\n";
11
12// regular array
13$fruits = array("lemon", "orange", "banana", "apple");
14
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
19 */
20function test_print($item, $key)
21{
22   // dump the arguments to check that they are passed
23   // with proper type
24   var_dump($item); // value
25   var_dump($key);  // key
26   echo "\n"; // new line to separate the output between each element
27}
28function with_userdata($item, $key, $user_data)
29{
30   // dump the arguments to check that they are passed
31   // with proper type
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
36}
37
38echo "-- Using array_walk() with default parameters to show array contents --\n";
39var_dump( array_walk($fruits, 'test_print'));
40
41echo "-- Using array_walk() with all parameters --\n";
42var_dump( array_walk($fruits, 'with_userdata', "Added"));
43
44echo "Done";
45?>
46--EXPECT--
47*** Testing array_walk() : basic functionality ***
48-- Using array_walk() with default parameters to show array contents --
49string(5) "lemon"
50int(0)
51
52string(6) "orange"
53int(1)
54
55string(6) "banana"
56int(2)
57
58string(5) "apple"
59int(3)
60
61bool(true)
62-- Using array_walk() with all parameters --
63string(5) "lemon"
64int(0)
65string(5) "Added"
66
67string(6) "orange"
68int(1)
69string(5) "Added"
70
71string(6) "banana"
72int(2)
73string(5) "Added"
74
75string(5) "apple"
76int(3)
77string(5) "Added"
78
79bool(true)
80Done
81