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       // float data
36/*2*/  'float' => array(
37       10.5 => 'positive',
38       -10.5 => 'negative',
39       .5 => 'half',
40       ),
41
42/*3*/  'extreme floats' => array(
43       12.3456789000e10 => 'large',
44       12.3456789000E-10 => 'small',
45       ),
46
47       // null data
48/*4*/  'null uppercase' => array(
49       NULL => 'null 1',
50       ),
51
52/*5*/  'null lowercase' => array(
53       null => 'null 2',
54       ),
55
56       // boolean data
57/*6*/ 'bool lowercase' => array(
58       true => 'lowert',
59       false => 'lowerf',
60       ),
61
62/*7*/  'bool uppercase' => array(
63       TRUE => 'uppert',
64       FALSE => 'upperf',
65       ),
66
67       // empty data
68/*8*/ 'empty double quotes' => array(
69       "" => 'emptyd',
70       ),
71
72/*9*/  'empty single quotes' => array(
73       '' => 'emptys',
74       ),
75
76       // string data
77/*10*/ 'string' => array(
78       "stringd" => 'stringd',
79       'strings' => 'strings',
80       $heredoc => 'stringh',
81       ),
82
83       // undefined data
84/*11*/ 'undefined' => array(
85       @$undefined_var => 'undefined',
86       ),
87
88       // unset data
89/*12*/ 'unset' => array(
90       @$unset_var => 'unset',
91       ),
92);
93
94// loop through each element of $inputs to check the behavior of array_merge
95$iterator = 1;
96foreach($inputs as $key => $input) {
97  echo "\n-- Iteration $iterator: $key data --\n";
98  var_dump( array_merge($input, $arr) );
99  var_dump( array_merge($arr, $input) );
100  $iterator++;
101};
102
103echo "Done";
104?>
105--EXPECT--
106*** Testing array_merge() : usage variations ***
107
108-- Iteration 1: int data --
109array(6) {
110  [0]=>
111  string(4) "zero"
112  [1]=>
113  string(3) "one"
114  [2]=>
115  string(8) "positive"
116  [3]=>
117  string(8) "negative"
118  ["one"]=>
119  int(1)
120  ["two"]=>
121  int(2)
122}
123array(6) {
124  ["one"]=>
125  int(1)
126  ["two"]=>
127  int(2)
128  [0]=>
129  string(4) "zero"
130  [1]=>
131  string(3) "one"
132  [2]=>
133  string(8) "positive"
134  [3]=>
135  string(8) "negative"
136}
137
138-- Iteration 2: float data --
139array(5) {
140  [0]=>
141  string(8) "positive"
142  [1]=>
143  string(8) "negative"
144  [2]=>
145  string(4) "half"
146  ["one"]=>
147  int(1)
148  ["two"]=>
149  int(2)
150}
151array(5) {
152  ["one"]=>
153  int(1)
154  ["two"]=>
155  int(2)
156  [0]=>
157  string(8) "positive"
158  [1]=>
159  string(8) "negative"
160  [2]=>
161  string(4) "half"
162}
163
164-- Iteration 3: extreme floats data --
165array(4) {
166  [0]=>
167  string(5) "large"
168  [1]=>
169  string(5) "small"
170  ["one"]=>
171  int(1)
172  ["two"]=>
173  int(2)
174}
175array(4) {
176  ["one"]=>
177  int(1)
178  ["two"]=>
179  int(2)
180  [0]=>
181  string(5) "large"
182  [1]=>
183  string(5) "small"
184}
185
186-- Iteration 4: null uppercase data --
187array(3) {
188  [""]=>
189  string(6) "null 1"
190  ["one"]=>
191  int(1)
192  ["two"]=>
193  int(2)
194}
195array(3) {
196  ["one"]=>
197  int(1)
198  ["two"]=>
199  int(2)
200  [""]=>
201  string(6) "null 1"
202}
203
204-- Iteration 5: null lowercase data --
205array(3) {
206  [""]=>
207  string(6) "null 2"
208  ["one"]=>
209  int(1)
210  ["two"]=>
211  int(2)
212}
213array(3) {
214  ["one"]=>
215  int(1)
216  ["two"]=>
217  int(2)
218  [""]=>
219  string(6) "null 2"
220}
221
222-- Iteration 6: bool lowercase data --
223array(4) {
224  [0]=>
225  string(6) "lowert"
226  [1]=>
227  string(6) "lowerf"
228  ["one"]=>
229  int(1)
230  ["two"]=>
231  int(2)
232}
233array(4) {
234  ["one"]=>
235  int(1)
236  ["two"]=>
237  int(2)
238  [0]=>
239  string(6) "lowert"
240  [1]=>
241  string(6) "lowerf"
242}
243
244-- Iteration 7: bool uppercase data --
245array(4) {
246  [0]=>
247  string(6) "uppert"
248  [1]=>
249  string(6) "upperf"
250  ["one"]=>
251  int(1)
252  ["two"]=>
253  int(2)
254}
255array(4) {
256  ["one"]=>
257  int(1)
258  ["two"]=>
259  int(2)
260  [0]=>
261  string(6) "uppert"
262  [1]=>
263  string(6) "upperf"
264}
265
266-- Iteration 8: empty double quotes data --
267array(3) {
268  [""]=>
269  string(6) "emptyd"
270  ["one"]=>
271  int(1)
272  ["two"]=>
273  int(2)
274}
275array(3) {
276  ["one"]=>
277  int(1)
278  ["two"]=>
279  int(2)
280  [""]=>
281  string(6) "emptyd"
282}
283
284-- Iteration 9: empty single quotes data --
285array(3) {
286  [""]=>
287  string(6) "emptys"
288  ["one"]=>
289  int(1)
290  ["two"]=>
291  int(2)
292}
293array(3) {
294  ["one"]=>
295  int(1)
296  ["two"]=>
297  int(2)
298  [""]=>
299  string(6) "emptys"
300}
301
302-- Iteration 10: string data --
303array(5) {
304  ["stringd"]=>
305  string(7) "stringd"
306  ["strings"]=>
307  string(7) "strings"
308  ["hello world"]=>
309  string(7) "stringh"
310  ["one"]=>
311  int(1)
312  ["two"]=>
313  int(2)
314}
315array(5) {
316  ["one"]=>
317  int(1)
318  ["two"]=>
319  int(2)
320  ["stringd"]=>
321  string(7) "stringd"
322  ["strings"]=>
323  string(7) "strings"
324  ["hello world"]=>
325  string(7) "stringh"
326}
327
328-- Iteration 11: undefined data --
329array(3) {
330  [""]=>
331  string(9) "undefined"
332  ["one"]=>
333  int(1)
334  ["two"]=>
335  int(2)
336}
337array(3) {
338  ["one"]=>
339  int(1)
340  ["two"]=>
341  int(2)
342  [""]=>
343  string(9) "undefined"
344}
345
346-- Iteration 12: unset data --
347array(3) {
348  [""]=>
349  string(5) "unset"
350  ["one"]=>
351  int(1)
352  ["two"]=>
353  int(2)
354}
355array(3) {
356  ["one"]=>
357  int(1)
358  ["two"]=>
359  int(2)
360  [""]=>
361  string(5) "unset"
362}
363Done
364