1b1f1babaSRaghubansh Kumar--TEST--
2b1f1babaSRaghubansh KumarTest array_walk_recursive() function : basic functionality - associative array
3b1f1babaSRaghubansh Kumar--FILE--
4b1f1babaSRaghubansh Kumar<?php
5b1f1babaSRaghubansh Kumar/* Prototype  : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata])
6782352c5SPeter Kokot * Description: Apply a user function to every member of an array
7b1f1babaSRaghubansh Kumar * Source code: ext/standard/array.c
8b1f1babaSRaghubansh Kumar*/
9b1f1babaSRaghubansh Kumar
10b1f1babaSRaghubansh Kumarecho "*** Testing array_walk_recursive() : basic functionality ***\n";
11b1f1babaSRaghubansh Kumar
12b1f1babaSRaghubansh Kumar// associative array
13b1f1babaSRaghubansh Kumar$fruits = array("a" => "lemon", "b" => array( "c" => "orange", "d" => "banana"), "e" => array("f" => "apple"));
14b1f1babaSRaghubansh Kumar
15b1f1babaSRaghubansh Kumar// User defined callback functions
16b1f1babaSRaghubansh Kumar/*  Prototype : test_alter(mixed $item, mixed $key, string $prefix)
17782352c5SPeter Kokot *  Parameters : item - value in key/value pair
18b1f1babaSRaghubansh Kumar *               key - key in key/value pair
19782352c5SPeter Kokot *               prefix - string to be added
20b1f1babaSRaghubansh Kumar *  Description : alters the array values by appending prefix string
21782352c5SPeter Kokot */
22b1f1babaSRaghubansh Kumarfunction test_alter(&$item, $key, $prefix)
23b1f1babaSRaghubansh Kumar{
24b1f1babaSRaghubansh Kumar  // dump the arguments to check that they are passed
25b1f1babaSRaghubansh Kumar  // with proper type
26b1f1babaSRaghubansh Kumar  var_dump($item); // value
27b1f1babaSRaghubansh Kumar  var_dump($key);  // key
2804145dc2SVeres Lajos  var_dump($prefix); // additional argument passed to callback function
29b1f1babaSRaghubansh Kumar  echo "\n"; // new line to separate the output between each element
30b1f1babaSRaghubansh Kumar}
31b1f1babaSRaghubansh Kumar
32b1f1babaSRaghubansh Kumar/*  Prototype : test_print(mixed $item, mixed $key)
33782352c5SPeter Kokot *  Parameters : item - value in key/value pair
34b1f1babaSRaghubansh Kumar *               key - key in key/value pair
35b1f1babaSRaghubansh Kumar *  Description : prints the array values with keys
36b1f1babaSRaghubansh Kumar */
37b1f1babaSRaghubansh Kumarfunction test_print($item, $key)
38b1f1babaSRaghubansh Kumar{
39b1f1babaSRaghubansh Kumar  // dump the arguments to check that they are passed
40b1f1babaSRaghubansh Kumar  // with proper type
41b1f1babaSRaghubansh Kumar  var_dump($item); // value
42b1f1babaSRaghubansh Kumar  var_dump($key);  // key
43b1f1babaSRaghubansh Kumar  echo "\n"; // new line to separate the output between each element
44b1f1babaSRaghubansh Kumar}
45b1f1babaSRaghubansh Kumar
46b1f1babaSRaghubansh Kumarecho "-- Using array_walk_recursive with default parameters to show array contents --\n";
47b1f1babaSRaghubansh Kumarvar_dump(array_walk_recursive($fruits, 'test_print'));
48b1f1babaSRaghubansh Kumar
49b1f1babaSRaghubansh Kumarecho "-- Using array_walk_recursive with one optional parameter to modify contents --\n";
50b1f1babaSRaghubansh Kumarvar_dump (array_walk_recursive($fruits, 'test_alter', 'fruit'));
51b1f1babaSRaghubansh Kumar
52b1f1babaSRaghubansh Kumarecho "-- Using array_walk_recursive with default parameters to show modified array contents --\n";
53b1f1babaSRaghubansh Kumarvar_dump (array_walk_recursive($fruits, 'test_print'));
54b1f1babaSRaghubansh Kumar
55b1f1babaSRaghubansh Kumarecho "Done";
56b1f1babaSRaghubansh Kumar?>
57b1f1babaSRaghubansh Kumar--EXPECT--
58b1f1babaSRaghubansh Kumar*** Testing array_walk_recursive() : basic functionality ***
59b1f1babaSRaghubansh Kumar-- Using array_walk_recursive with default parameters to show array contents --
60b1f1babaSRaghubansh Kumarstring(5) "lemon"
61b1f1babaSRaghubansh Kumarstring(1) "a"
62b1f1babaSRaghubansh Kumar
63b1f1babaSRaghubansh Kumarstring(6) "orange"
64b1f1babaSRaghubansh Kumarstring(1) "c"
65b1f1babaSRaghubansh Kumar
66b1f1babaSRaghubansh Kumarstring(6) "banana"
67b1f1babaSRaghubansh Kumarstring(1) "d"
68b1f1babaSRaghubansh Kumar
69b1f1babaSRaghubansh Kumarstring(5) "apple"
70b1f1babaSRaghubansh Kumarstring(1) "f"
71b1f1babaSRaghubansh Kumar
72b1f1babaSRaghubansh Kumarbool(true)
73b1f1babaSRaghubansh Kumar-- Using array_walk_recursive with one optional parameter to modify contents --
74b1f1babaSRaghubansh Kumarstring(5) "lemon"
75b1f1babaSRaghubansh Kumarstring(1) "a"
76b1f1babaSRaghubansh Kumarstring(5) "fruit"
77b1f1babaSRaghubansh Kumar
78b1f1babaSRaghubansh Kumarstring(6) "orange"
79b1f1babaSRaghubansh Kumarstring(1) "c"
80b1f1babaSRaghubansh Kumarstring(5) "fruit"
81b1f1babaSRaghubansh Kumar
82b1f1babaSRaghubansh Kumarstring(6) "banana"
83b1f1babaSRaghubansh Kumarstring(1) "d"
84b1f1babaSRaghubansh Kumarstring(5) "fruit"
85b1f1babaSRaghubansh Kumar
86b1f1babaSRaghubansh Kumarstring(5) "apple"
87b1f1babaSRaghubansh Kumarstring(1) "f"
88b1f1babaSRaghubansh Kumarstring(5) "fruit"
89b1f1babaSRaghubansh Kumar
90b1f1babaSRaghubansh Kumarbool(true)
91b1f1babaSRaghubansh Kumar-- Using array_walk_recursive with default parameters to show modified array contents --
92b1f1babaSRaghubansh Kumarstring(5) "lemon"
93b1f1babaSRaghubansh Kumarstring(1) "a"
94b1f1babaSRaghubansh Kumar
95b1f1babaSRaghubansh Kumarstring(6) "orange"
96b1f1babaSRaghubansh Kumarstring(1) "c"
97b1f1babaSRaghubansh Kumar
98b1f1babaSRaghubansh Kumarstring(6) "banana"
99b1f1babaSRaghubansh Kumarstring(1) "d"
100b1f1babaSRaghubansh Kumar
101b1f1babaSRaghubansh Kumarstring(5) "apple"
102b1f1babaSRaghubansh Kumarstring(1) "f"
103b1f1babaSRaghubansh Kumar
104b1f1babaSRaghubansh Kumarbool(true)
105b1f1babaSRaghubansh KumarDone
106