1--TEST--
2Test array_merge_recursive() function : usage variations - two dimensional arrays
3--FILE--
4<?php
5/*
6 * Testing the functionality of array_merge_recursive() by passing
7 * two dimensional arrays for $arr1 argument.
8*/
9
10echo "*** Testing array_merge_recursive() : two dimensional array for \$arr1 argument ***\n";
11
12// initialize the 2-d array
13$arr1 = array(
14  array(1, 2, 3, 1),
15  "array" => array("hello", "world", "str1" => "hello", "str2" => 'world'),
16  array(1 => "one", 2 => "two", "one", 'two'),
17  array(1, 2, 3, 1)
18);
19
20// initialize the second argument
21$arr2 = array(1, "hello", "array" => array("hello", 'world'));
22
23echo "-- Passing the entire 2-d array --\n";
24echo "-- With default argument --\n";
25var_dump( array_merge_recursive($arr1) );
26echo "-- With more arguments --\n";
27var_dump( array_merge_recursive($arr1, $arr2) );
28
29echo "-- Passing the sub-array --\n";
30echo "-- With default argument --\n";
31var_dump( array_merge_recursive($arr1["array"]) );
32echo "-- With more arguments --\n";
33var_dump( array_merge_recursive($arr1["array"], $arr2["array"]) );
34
35echo "Done";
36?>
37--EXPECT--
38*** Testing array_merge_recursive() : two dimensional array for $arr1 argument ***
39-- Passing the entire 2-d array --
40-- With default argument --
41array(4) {
42  [0]=>
43  array(4) {
44    [0]=>
45    int(1)
46    [1]=>
47    int(2)
48    [2]=>
49    int(3)
50    [3]=>
51    int(1)
52  }
53  ["array"]=>
54  array(4) {
55    [0]=>
56    string(5) "hello"
57    [1]=>
58    string(5) "world"
59    ["str1"]=>
60    string(5) "hello"
61    ["str2"]=>
62    string(5) "world"
63  }
64  [1]=>
65  array(4) {
66    [1]=>
67    string(3) "one"
68    [2]=>
69    string(3) "two"
70    [3]=>
71    string(3) "one"
72    [4]=>
73    string(3) "two"
74  }
75  [2]=>
76  array(4) {
77    [0]=>
78    int(1)
79    [1]=>
80    int(2)
81    [2]=>
82    int(3)
83    [3]=>
84    int(1)
85  }
86}
87-- With more arguments --
88array(6) {
89  [0]=>
90  array(4) {
91    [0]=>
92    int(1)
93    [1]=>
94    int(2)
95    [2]=>
96    int(3)
97    [3]=>
98    int(1)
99  }
100  ["array"]=>
101  array(6) {
102    [0]=>
103    string(5) "hello"
104    [1]=>
105    string(5) "world"
106    ["str1"]=>
107    string(5) "hello"
108    ["str2"]=>
109    string(5) "world"
110    [2]=>
111    string(5) "hello"
112    [3]=>
113    string(5) "world"
114  }
115  [1]=>
116  array(4) {
117    [1]=>
118    string(3) "one"
119    [2]=>
120    string(3) "two"
121    [3]=>
122    string(3) "one"
123    [4]=>
124    string(3) "two"
125  }
126  [2]=>
127  array(4) {
128    [0]=>
129    int(1)
130    [1]=>
131    int(2)
132    [2]=>
133    int(3)
134    [3]=>
135    int(1)
136  }
137  [3]=>
138  int(1)
139  [4]=>
140  string(5) "hello"
141}
142-- Passing the sub-array --
143-- With default argument --
144array(4) {
145  [0]=>
146  string(5) "hello"
147  [1]=>
148  string(5) "world"
149  ["str1"]=>
150  string(5) "hello"
151  ["str2"]=>
152  string(5) "world"
153}
154-- With more arguments --
155array(6) {
156  [0]=>
157  string(5) "hello"
158  [1]=>
159  string(5) "world"
160  ["str1"]=>
161  string(5) "hello"
162  ["str2"]=>
163  string(5) "world"
164  [2]=>
165  string(5) "hello"
166  [3]=>
167  string(5) "world"
168}
169Done
170