Annotation of embedaddon/php/ext/standard/tests/array/array_walk_recursive_basic2.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test array_walk_recursive() function : basic functionality - associative array
3: --FILE--
4: <?php
5: /* Prototype : bool array_walk_recursive(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:
10: echo "*** Testing array_walk_recursive() : basic functionality ***\n";
11:
12: // associative array
13: $fruits = array("a" => "lemon", "b" => array( "c" => "orange", "d" => "banana"), "e" => array("f" => "apple"));
14:
15: // User defined callback functions
16: /* Prototype : test_alter(mixed $item, mixed $key, string $prefix)
17: * Parameters : item - value in key/value pair
18: * key - key in key/value pair
19: * prefix - string to be added
20: * Description : alters the array values by appending prefix string
21: */
22: function test_alter(&$item, $key, $prefix)
23: {
24: // dump the arguments to check that they are passed
25: // with proper type
26: var_dump($item); // value
27: var_dump($key); // key
1.1.1.2 ! misho 28: var_dump($prefix); // additional argument passed to callback function
1.1 misho 29: echo "\n"; // new line to separate the output between each element
30: }
31:
32: /* Prototype : test_print(mixed $item, mixed $key)
33: * Parameters : item - value in key/value pair
34: * key - key in key/value pair
35: * Description : prints the array values with keys
36: */
37: function test_print($item, $key)
38: {
39: // dump the arguments to check that they are passed
40: // with proper type
41: var_dump($item); // value
42: var_dump($key); // key
43: echo "\n"; // new line to separate the output between each element
44: }
45:
46: echo "-- Using array_walk_recursive with default parameters to show array contents --\n";
47: var_dump(array_walk_recursive($fruits, 'test_print'));
48:
49: echo "-- Using array_walk_recursive with one optional parameter to modify contents --\n";
50: var_dump (array_walk_recursive($fruits, 'test_alter', 'fruit'));
51:
52: echo "-- Using array_walk_recursive with default parameters to show modified array contents --\n";
53: var_dump (array_walk_recursive($fruits, 'test_print'));
54:
55: echo "Done";
56: ?>
57: --EXPECT--
58: *** Testing array_walk_recursive() : basic functionality ***
59: -- Using array_walk_recursive with default parameters to show array contents --
60: string(5) "lemon"
61: string(1) "a"
62:
63: string(6) "orange"
64: string(1) "c"
65:
66: string(6) "banana"
67: string(1) "d"
68:
69: string(5) "apple"
70: string(1) "f"
71:
72: bool(true)
73: -- Using array_walk_recursive with one optional parameter to modify contents --
74: string(5) "lemon"
75: string(1) "a"
76: string(5) "fruit"
77:
78: string(6) "orange"
79: string(1) "c"
80: string(5) "fruit"
81:
82: string(6) "banana"
83: string(1) "d"
84: string(5) "fruit"
85:
86: string(5) "apple"
87: string(1) "f"
88: string(5) "fruit"
89:
90: bool(true)
91: -- Using array_walk_recursive with default parameters to show modified array contents --
92: string(5) "lemon"
93: string(1) "a"
94:
95: string(6) "orange"
96: string(1) "c"
97:
98: string(6) "banana"
99: string(1) "d"
100:
101: string(5) "apple"
102: string(1) "f"
103:
104: bool(true)
105: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>