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