Updates to Tomato RAF including NGINX && PHP
[tomato.git] / release / src / router / php / ext / standard / tests / array / array_walk_basic2.phpt
blobe856b580ba79e4179b514a58991491322df8199f
1 --TEST--
2 Test array_walk() function : basic functionality - associative 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 */
10 echo "*** Testing array_walk() : basic functionality ***\n";
12 // associative array
13 $fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
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)
24   // dump the arguments to check that they are passed
25   // with proper type
26   var_dump($item); // value
27   var_dump($key);  // key
28   var_dump($prefix); // additional agument passed to callback function
29   echo "\n"; // new line to separate the output between each element
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)
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
46 echo "-- Using array_walk with default parameters to show array contents --\n";
47 var_dump(array_walk($fruits, 'test_print'));
49 echo "-- Using array_walk with one optional parameter to modify contents --\n";
50 var_dump (array_walk($fruits, 'test_alter', 'fruit'));
52 echo "-- Using array_walk with default parameters to show modified array contents --\n";
53 var_dump (array_walk($fruits, 'test_print'));
55 echo "Done";
57 --EXPECT--
58 *** Testing array_walk() : basic functionality ***
59 -- Using array_walk with default parameters to show array contents --
60 string(5) "lemon"
61 string(1) "d"
63 string(6) "orange"
64 string(1) "a"
66 string(6) "banana"
67 string(1) "b"
69 string(5) "apple"
70 string(1) "c"
72 bool(true)
73 -- Using array_walk with one optional parameter to modify contents --
74 string(5) "lemon"
75 string(1) "d"
76 string(5) "fruit"
78 string(6) "orange"
79 string(1) "a"
80 string(5) "fruit"
82 string(6) "banana"
83 string(1) "b"
84 string(5) "fruit"
86 string(5) "apple"
87 string(1) "c"
88 string(5) "fruit"
90 bool(true)
91 -- Using array_walk with default parameters to show modified array contents --
92 string(5) "lemon"
93 string(1) "d"
95 string(6) "orange"
96 string(1) "a"
98 string(6) "banana"
99 string(1) "b"
101 string(5) "apple"
102 string(1) "c"
104 bool(true)
105 Done