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