1--TEST--
2Test array_merge_recursive() function : usage variations - different arrays for 'arr1' argument
3--FILE--
4<?php
5/*
6* Passing different arrays to $arr1 argument and testing whether
7* array_merge_recursive() behaves in an expected way.
8*/
9
10echo "*** Testing array_merge_recursive() : Passing different arrays to \$arr1 argument ***\n";
11
12/* Different heredoc strings */
13
14// heredoc with blank line
15$blank_line = <<<EOT
16
17
18EOT;
19
20// heredoc with multiline string
21$multiline_string = <<<EOT
22hello world
23The quick brown fox jumped over;
24the lazy dog
25This is a double quoted string
26EOT;
27
28// heredoc with different whitespaces
29$diff_whitespaces = <<<EOT
30hello\r world\t
311111\t\t != 2222\v\v
32heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces
33EOT;
34
35// heredoc with quoted strings and numeric values
36$numeric_string = <<<EOT
3711 < 12. 123 >22
38'single quoted string'
39"double quoted string"
402222 != 1111.\t 0000 = 0000\n
41EOT;
42
43// arrays passed to $arr1 argument
44$arrays = array (
45/*1*/  array(1, 2,), // with default keys and numeric values
46       array(1.1, 2.2), // with default keys & float values
47       array(false, true), // with default keys and boolean values
48       array(), // empty array
49/*5*/  array(NULL), // with NULL
50       array("a\v\f", "aaaa\r", "b", "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"),  // with double quoted strings
51       array('a\v\f', 'aaaa\r', 'b', '\[\]\!\@\#\$\%\^\&\*\(\)\{\}'),  // with single quoted strings
52       array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces),  // with heredocs
53
54       // associative arrays
55/*9*/  array(1 => "one", 2 => "two"),  // explicit numeric keys, string values
56       array("one" => 1, "two" => 2, "1" => 1 ),  // string keys & numeric values
57       array( 1 => 10, 2 => 20, 4 => 40),  // explicit numeric keys and numeric values
58       array( "one" => "ten", "two" => "twenty"),  // string key/value
59       array("one" => 1, 2 => "two", 4 => "four"),  //mixed
60
61       // associative array, containing null/empty/boolean values as key/value
62/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null),
63       array(true => "true", false => "false", "false" => false, "true" => true),
64       array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''),
65       array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true),
66       array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6),
67
68       // array containing embedded arrays
69/*15*/ array("str1", "array" => array("hello", 'world'), array(1, 2))
70);
71
72// initialise the second argument
73$arr2 = array( 1 => "one", 2, "string" => "hello", "array" => array("a", "b", "c"));
74
75// loop through each sub array of $arrays and check the behavior of array_merge_recursive()
76$iterator = 1;
77foreach($arrays as $arr1) {
78  echo "-- Iteration $iterator --\n";
79
80  // with default argument
81  echo "-- With default argument --\n";
82  var_dump( array_merge_recursive($arr1) );
83
84  // with more arguments
85  echo "-- With more arguments --\n";
86  var_dump( array_merge_recursive($arr1, $arr2) );
87
88  $iterator++;
89}
90
91echo "Done";
92?>
93--EXPECT--
94*** Testing array_merge_recursive() : Passing different arrays to $arr1 argument ***
95-- Iteration 1 --
96-- With default argument --
97array(2) {
98  [0]=>
99  int(1)
100  [1]=>
101  int(2)
102}
103-- With more arguments --
104array(6) {
105  [0]=>
106  int(1)
107  [1]=>
108  int(2)
109  [2]=>
110  string(3) "one"
111  [3]=>
112  int(2)
113  ["string"]=>
114  string(5) "hello"
115  ["array"]=>
116  array(3) {
117    [0]=>
118    string(1) "a"
119    [1]=>
120    string(1) "b"
121    [2]=>
122    string(1) "c"
123  }
124}
125-- Iteration 2 --
126-- With default argument --
127array(2) {
128  [0]=>
129  float(1.1)
130  [1]=>
131  float(2.2)
132}
133-- With more arguments --
134array(6) {
135  [0]=>
136  float(1.1)
137  [1]=>
138  float(2.2)
139  [2]=>
140  string(3) "one"
141  [3]=>
142  int(2)
143  ["string"]=>
144  string(5) "hello"
145  ["array"]=>
146  array(3) {
147    [0]=>
148    string(1) "a"
149    [1]=>
150    string(1) "b"
151    [2]=>
152    string(1) "c"
153  }
154}
155-- Iteration 3 --
156-- With default argument --
157array(2) {
158  [0]=>
159  bool(false)
160  [1]=>
161  bool(true)
162}
163-- With more arguments --
164array(6) {
165  [0]=>
166  bool(false)
167  [1]=>
168  bool(true)
169  [2]=>
170  string(3) "one"
171  [3]=>
172  int(2)
173  ["string"]=>
174  string(5) "hello"
175  ["array"]=>
176  array(3) {
177    [0]=>
178    string(1) "a"
179    [1]=>
180    string(1) "b"
181    [2]=>
182    string(1) "c"
183  }
184}
185-- Iteration 4 --
186-- With default argument --
187array(0) {
188}
189-- With more arguments --
190array(4) {
191  [0]=>
192  string(3) "one"
193  [1]=>
194  int(2)
195  ["string"]=>
196  string(5) "hello"
197  ["array"]=>
198  array(3) {
199    [0]=>
200    string(1) "a"
201    [1]=>
202    string(1) "b"
203    [2]=>
204    string(1) "c"
205  }
206}
207-- Iteration 5 --
208-- With default argument --
209array(1) {
210  [0]=>
211  NULL
212}
213-- With more arguments --
214array(5) {
215  [0]=>
216  NULL
217  [1]=>
218  string(3) "one"
219  [2]=>
220  int(2)
221  ["string"]=>
222  string(5) "hello"
223  ["array"]=>
224  array(3) {
225    [0]=>
226    string(1) "a"
227    [1]=>
228    string(1) "b"
229    [2]=>
230    string(1) "c"
231  }
232}
233-- Iteration 6 --
234-- With default argument --
235array(4) {
236  [0]=>
237  string(3) "a"
238  [1]=>
239  string(5) "aaaa
239"
240  [2]=>
241  string(1) "b"
242  [3]=>
243  string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}"
244}
245-- With more arguments --
246array(8) {
247  [0]=>
248  string(3) "a"
249  [1]=>
250  string(5) "aaaa
250"
251  [2]=>
252  string(1) "b"
253  [3]=>
254  string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}"
255  [4]=>
256  string(3) "one"
257  [5]=>
258  int(2)
259  ["string"]=>
260  string(5) "hello"
261  ["array"]=>
262  array(3) {
263    [0]=>
264    string(1) "a"
265    [1]=>
266    string(1) "b"
267    [2]=>
268    string(1) "c"
269  }
270}
271-- Iteration 7 --
272-- With default argument --
273array(4) {
274  [0]=>
275  string(5) "a\v\f"
276  [1]=>
277  string(6) "aaaa\r"
278  [2]=>
279  string(1) "b"
280  [3]=>
281  string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"
282}
283-- With more arguments --
284array(8) {
285  [0]=>
286  string(5) "a\v\f"
287  [1]=>
288  string(6) "aaaa\r"
289  [2]=>
290  string(1) "b"
291  [3]=>
292  string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"
293  [4]=>
294  string(3) "one"
295  [5]=>
296  int(2)
297  ["string"]=>
298  string(5) "hello"
299  ["array"]=>
300  array(3) {
301    [0]=>
302    string(1) "a"
303    [1]=>
304    string(1) "b"
305    [2]=>
306    string(1) "c"
307  }
308}
309-- Iteration 8 --
310-- With default argument --
311array(3) {
312  ["h1"]=>
313  string(1) "
314"
315  ["h2"]=>
316  string(88) "hello world
317The quick brown fox jumped over;
318the lazy dog
319This is a double quoted string"
320  ["h3"]=>
321  string(88) "hello
321 world
3221111		 != 2222
323heredoc
324double quoted string. withdifferentwhitespaces"
325}
326-- With more arguments --
327array(7) {
328  ["h1"]=>
329  string(1) "
330"
331  ["h2"]=>
332  string(88) "hello world
333The quick brown fox jumped over;
334the lazy dog
335This is a double quoted string"
336  ["h3"]=>
337  string(88) "hello
337 world
3381111		 != 2222
339heredoc
340double quoted string. withdifferentwhitespaces"
341  [0]=>
342  string(3) "one"
343  [1]=>
344  int(2)
345  ["string"]=>
346  string(5) "hello"
347  ["array"]=>
348  array(3) {
349    [0]=>
350    string(1) "a"
351    [1]=>
352    string(1) "b"
353    [2]=>
354    string(1) "c"
355  }
356}
357-- Iteration 9 --
358-- With default argument --
359array(2) {
360  [0]=>
361  string(3) "one"
362  [1]=>
363  string(3) "two"
364}
365-- With more arguments --
366array(6) {
367  [0]=>
368  string(3) "one"
369  [1]=>
370  string(3) "two"
371  [2]=>
372  string(3) "one"
373  [3]=>
374  int(2)
375  ["string"]=>
376  string(5) "hello"
377  ["array"]=>
378  array(3) {
379    [0]=>
380    string(1) "a"
381    [1]=>
382    string(1) "b"
383    [2]=>
384    string(1) "c"
385  }
386}
387-- Iteration 10 --
388-- With default argument --
389array(3) {
390  ["one"]=>
391  int(1)
392  ["two"]=>
393  int(2)
394  [0]=>
395  int(1)
396}
397-- With more arguments --
398array(7) {
399  ["one"]=>
400  int(1)
401  ["two"]=>
402  int(2)
403  [0]=>
404  int(1)
405  [1]=>
406  string(3) "one"
407  [2]=>
408  int(2)
409  ["string"]=>
410  string(5) "hello"
411  ["array"]=>
412  array(3) {
413    [0]=>
414    string(1) "a"
415    [1]=>
416    string(1) "b"
417    [2]=>
418    string(1) "c"
419  }
420}
421-- Iteration 11 --
422-- With default argument --
423array(3) {
424  [0]=>
425  int(10)
426  [1]=>
427  int(20)
428  [2]=>
429  int(40)
430}
431-- With more arguments --
432array(7) {
433  [0]=>
434  int(10)
435  [1]=>
436  int(20)
437  [2]=>
438  int(40)
439  [3]=>
440  string(3) "one"
441  [4]=>
442  int(2)
443  ["string"]=>
444  string(5) "hello"
445  ["array"]=>
446  array(3) {
447    [0]=>
448    string(1) "a"
449    [1]=>
450    string(1) "b"
451    [2]=>
452    string(1) "c"
453  }
454}
455-- Iteration 12 --
456-- With default argument --
457array(2) {
458  ["one"]=>
459  string(3) "ten"
460  ["two"]=>
461  string(6) "twenty"
462}
463-- With more arguments --
464array(6) {
465  ["one"]=>
466  string(3) "ten"
467  ["two"]=>
468  string(6) "twenty"
469  [0]=>
470  string(3) "one"
471  [1]=>
472  int(2)
473  ["string"]=>
474  string(5) "hello"
475  ["array"]=>
476  array(3) {
477    [0]=>
478    string(1) "a"
479    [1]=>
480    string(1) "b"
481    [2]=>
482    string(1) "c"
483  }
484}
485-- Iteration 13 --
486-- With default argument --
487array(3) {
488  ["one"]=>
489  int(1)
490  [0]=>
491  string(3) "two"
492  [1]=>
493  string(4) "four"
494}
495-- With more arguments --
496array(7) {
497  ["one"]=>
498  int(1)
499  [0]=>
500  string(3) "two"
501  [1]=>
502  string(4) "four"
503  [2]=>
504  string(3) "one"
505  [3]=>
506  int(2)
507  ["string"]=>
508  string(5) "hello"
509  ["array"]=>
510  array(3) {
511    [0]=>
512    string(1) "a"
513    [1]=>
514    string(1) "b"
515    [2]=>
516    string(1) "c"
517  }
518}
519-- Iteration 14 --
520-- With default argument --
521array(3) {
522  [""]=>
523  string(4) "null"
524  ["NULL"]=>
525  NULL
526  ["null"]=>
527  NULL
528}
529-- With more arguments --
530array(7) {
531  [""]=>
532  string(4) "null"
533  ["NULL"]=>
534  NULL
535  ["null"]=>
536  NULL
537  [0]=>
538  string(3) "one"
539  [1]=>
540  int(2)
541  ["string"]=>
542  string(5) "hello"
543  ["array"]=>
544  array(3) {
545    [0]=>
546    string(1) "a"
547    [1]=>
548    string(1) "b"
549    [2]=>
550    string(1) "c"
551  }
552}
553-- Iteration 15 --
554-- With default argument --
555array(4) {
556  [0]=>
557  string(4) "true"
558  [1]=>
559  string(5) "false"
560  ["false"]=>
561  bool(false)
562  ["true"]=>
563  bool(true)
564}
565-- With more arguments --
566array(8) {
567  [0]=>
568  string(4) "true"
569  [1]=>
570  string(5) "false"
571  ["false"]=>
572  bool(false)
573  ["true"]=>
574  bool(true)
575  [2]=>
576  string(3) "one"
577  [3]=>
578  int(2)
579  ["string"]=>
580  string(5) "hello"
581  ["array"]=>
582  array(3) {
583    [0]=>
584    string(1) "a"
585    [1]=>
586    string(1) "b"
587    [2]=>
588    string(1) "c"
589  }
590}
591-- Iteration 16 --
592-- With default argument --
593array(3) {
594  [""]=>
595  string(6) "emptys"
596  ["emptyd"]=>
597  string(0) ""
598  ["emptys"]=>
599  string(0) ""
600}
601-- With more arguments --
602array(7) {
603  [""]=>
604  string(6) "emptys"
605  ["emptyd"]=>
606  string(0) ""
607  ["emptys"]=>
608  string(0) ""
609  [0]=>
610  string(3) "one"
611  [1]=>
612  int(2)
613  ["string"]=>
614  string(5) "hello"
615  ["array"]=>
616  array(3) {
617    [0]=>
618    string(1) "a"
619    [1]=>
620    string(1) "b"
621    [2]=>
622    string(1) "c"
623  }
624}
625-- Iteration 17 --
626-- With default argument --
627array(6) {
628  [0]=>
629  string(0) ""
630  [1]=>
631  string(0) ""
632  [2]=>
633  NULL
634  [3]=>
635  NULL
636  [4]=>
637  bool(false)
638  [5]=>
639  bool(true)
640}
641-- With more arguments --
642array(10) {
643  [0]=>
644  string(0) ""
645  [1]=>
646  string(0) ""
647  [2]=>
648  NULL
649  [3]=>
650  NULL
651  [4]=>
652  bool(false)
653  [5]=>
654  bool(true)
655  [6]=>
656  string(3) "one"
657  [7]=>
658  int(2)
659  ["string"]=>
660  string(5) "hello"
661  ["array"]=>
662  array(3) {
663    [0]=>
664    string(1) "a"
665    [1]=>
666    string(1) "b"
667    [2]=>
668    string(1) "c"
669  }
670}
671-- Iteration 18 --
672-- With default argument --
673array(3) {
674  [""]=>
675  int(4)
676  [0]=>
677  int(5)
678  [1]=>
679  int(6)
680}
681-- With more arguments --
682array(7) {
683  [""]=>
684  int(4)
685  [0]=>
686  int(5)
687  [1]=>
688  int(6)
689  [2]=>
690  string(3) "one"
691  [3]=>
692  int(2)
693  ["string"]=>
694  string(5) "hello"
695  ["array"]=>
696  array(3) {
697    [0]=>
698    string(1) "a"
699    [1]=>
700    string(1) "b"
701    [2]=>
702    string(1) "c"
703  }
704}
705-- Iteration 19 --
706-- With default argument --
707array(3) {
708  [0]=>
709  string(4) "str1"
710  ["array"]=>
711  array(2) {
712    [0]=>
713    string(5) "hello"
714    [1]=>
715    string(5) "world"
716  }
717  [1]=>
718  array(2) {
719    [0]=>
720    int(1)
721    [1]=>
722    int(2)
723  }
724}
725-- With more arguments --
726array(6) {
727  [0]=>
728  string(4) "str1"
729  ["array"]=>
730  array(5) {
731    [0]=>
732    string(5) "hello"
733    [1]=>
734    string(5) "world"
735    [2]=>
736    string(1) "a"
737    [3]=>
738    string(1) "b"
739    [4]=>
740    string(1) "c"
741  }
742  [1]=>
743  array(2) {
744    [0]=>
745    int(1)
746    [1]=>
747    int(2)
748  }
749  [2]=>
750  string(3) "one"
751  [3]=>
752  int(2)
753  ["string"]=>
754  string(5) "hello"
755}
756Done
757