1--TEST--
2Test array_merge() function : usage variations - Diff. data types as array keys
3--FILE--
4<?php
5/*
6 * Pass an array with different data types as keys to test how array_merge
7 * adds it onto an existing array
8 */
9
10echo "*** Testing array_merge() : usage variations ***\n";
11
12// Initialise function arguments not being substituted
13$arr = array ('one' => 1, 'two' => 2);
14
15//get an unset variable
16$unset_var = 10;
17unset ($unset_var);
18
19// heredoc string
20$heredoc = <<<EOT
21hello world
22EOT;
23
24// arrays with keys as different data types to be passed as $input
25$inputs = array(
26
27       // int data
28/*1*/  'int' => array(
29       0 => 'zero',
30       1 => 'one',
31       12345 => 'positive',
32       -2345 => 'negative',
33       ),
34
35       // null data
36/*4*/  'null uppercase' => array(
37       NULL => 'null 1',
38       ),
39
40/*5*/  'null lowercase' => array(
41       null => 'null 2',
42       ),
43
44       // boolean data
45/*6*/ 'bool lowercase' => array(
46       true => 'lowert',
47       false => 'lowerf',
48       ),
49
50/*7*/  'bool uppercase' => array(
51       TRUE => 'uppert',
52       FALSE => 'upperf',
53       ),
54
55       // empty data
56/*8*/ 'empty double quotes' => array(
57       "" => 'emptyd',
58       ),
59
60/*9*/  'empty single quotes' => array(
61       '' => 'emptys',
62       ),
63
64       // string data
65/*10*/ 'string' => array(
66       "stringd" => 'stringd',
67       'strings' => 'strings',
68       $heredoc => 'stringh',
69       ),
70
71       // undefined data
72/*11*/ 'undefined' => array(
73       @$undefined_var => 'undefined',
74       ),
75
76       // unset data
77/*12*/ 'unset' => array(
78       @$unset_var => 'unset',
79       ),
80);
81
82// loop through each element of $inputs to check the behavior of array_merge
83$iterator = 1;
84foreach($inputs as $key => $input) {
85  echo "\n-- Iteration $iterator: $key data --\n";
86  var_dump( array_merge($input, $arr) );
87  var_dump( array_merge($arr, $input) );
88  $iterator++;
89};
90
91echo "Done";
92?>
93--EXPECT--
94*** Testing array_merge() : usage variations ***
95
96-- Iteration 1: int data --
97array(6) {
98  [0]=>
99  string(4) "zero"
100  [1]=>
101  string(3) "one"
102  [2]=>
103  string(8) "positive"
104  [3]=>
105  string(8) "negative"
106  ["one"]=>
107  int(1)
108  ["two"]=>
109  int(2)
110}
111array(6) {
112  ["one"]=>
113  int(1)
114  ["two"]=>
115  int(2)
116  [0]=>
117  string(4) "zero"
118  [1]=>
119  string(3) "one"
120  [2]=>
121  string(8) "positive"
122  [3]=>
123  string(8) "negative"
124}
125
126-- Iteration 2: null uppercase data --
127array(3) {
128  [""]=>
129  string(6) "null 1"
130  ["one"]=>
131  int(1)
132  ["two"]=>
133  int(2)
134}
135array(3) {
136  ["one"]=>
137  int(1)
138  ["two"]=>
139  int(2)
140  [""]=>
141  string(6) "null 1"
142}
143
144-- Iteration 3: null lowercase data --
145array(3) {
146  [""]=>
147  string(6) "null 2"
148  ["one"]=>
149  int(1)
150  ["two"]=>
151  int(2)
152}
153array(3) {
154  ["one"]=>
155  int(1)
156  ["two"]=>
157  int(2)
158  [""]=>
159  string(6) "null 2"
160}
161
162-- Iteration 4: bool lowercase data --
163array(4) {
164  [0]=>
165  string(6) "lowert"
166  [1]=>
167  string(6) "lowerf"
168  ["one"]=>
169  int(1)
170  ["two"]=>
171  int(2)
172}
173array(4) {
174  ["one"]=>
175  int(1)
176  ["two"]=>
177  int(2)
178  [0]=>
179  string(6) "lowert"
180  [1]=>
181  string(6) "lowerf"
182}
183
184-- Iteration 5: bool uppercase data --
185array(4) {
186  [0]=>
187  string(6) "uppert"
188  [1]=>
189  string(6) "upperf"
190  ["one"]=>
191  int(1)
192  ["two"]=>
193  int(2)
194}
195array(4) {
196  ["one"]=>
197  int(1)
198  ["two"]=>
199  int(2)
200  [0]=>
201  string(6) "uppert"
202  [1]=>
203  string(6) "upperf"
204}
205
206-- Iteration 6: empty double quotes data --
207array(3) {
208  [""]=>
209  string(6) "emptyd"
210  ["one"]=>
211  int(1)
212  ["two"]=>
213  int(2)
214}
215array(3) {
216  ["one"]=>
217  int(1)
218  ["two"]=>
219  int(2)
220  [""]=>
221  string(6) "emptyd"
222}
223
224-- Iteration 7: empty single quotes data --
225array(3) {
226  [""]=>
227  string(6) "emptys"
228  ["one"]=>
229  int(1)
230  ["two"]=>
231  int(2)
232}
233array(3) {
234  ["one"]=>
235  int(1)
236  ["two"]=>
237  int(2)
238  [""]=>
239  string(6) "emptys"
240}
241
242-- Iteration 8: string data --
243array(5) {
244  ["stringd"]=>
245  string(7) "stringd"
246  ["strings"]=>
247  string(7) "strings"
248  ["hello world"]=>
249  string(7) "stringh"
250  ["one"]=>
251  int(1)
252  ["two"]=>
253  int(2)
254}
255array(5) {
256  ["one"]=>
257  int(1)
258  ["two"]=>
259  int(2)
260  ["stringd"]=>
261  string(7) "stringd"
262  ["strings"]=>
263  string(7) "strings"
264  ["hello world"]=>
265  string(7) "stringh"
266}
267
268-- Iteration 9: undefined data --
269array(3) {
270  [""]=>
271  string(9) "undefined"
272  ["one"]=>
273  int(1)
274  ["two"]=>
275  int(2)
276}
277array(3) {
278  ["one"]=>
279  int(1)
280  ["two"]=>
281  int(2)
282  [""]=>
283  string(9) "undefined"
284}
285
286-- Iteration 10: unset data --
287array(3) {
288  [""]=>
289  string(5) "unset"
290  ["one"]=>
291  int(1)
292  ["two"]=>
293  int(2)
294}
295array(3) {
296  ["one"]=>
297  int(1)
298  ["two"]=>
299  int(2)
300  [""]=>
301  string(5) "unset"
302}
303Done
304