1--TEST--
2Test array_merge_recursive() function : usage variations - array with duplicate keys
3--FILE--
4<?php
5/*
6 * Testing the functionality of array_merge_recursive() by passing
7 * array having duplicate keys.
8*/
9
10echo "*** Testing array_merge_recursive() : array with duplicate keys for \$arr1 argument ***\n";
11
12/* initialize the array having duplicate keys */
13// array with numeric keys
14$arr1_numeric_key = array( 1 => "one", 2 => "two", 2 => array(1, 2), 3 => "three", 1 => array("duplicate", 'strings'));
15// array with string keys
16$arr1_string_key = array("str1" => "hello", "str2" => 111, "str1" => "world", "str2" => 111.111);
17
18// initialize the second argument
19$arr2 = array("one", "str1" => "two", array("one", "two"));
20
21echo "-- With default argument --\n";
22var_dump( array_merge_recursive($arr1_numeric_key) );
23var_dump( array_merge_recursive($arr1_string_key) );
24
25echo "-- With more arguments --\n";
26var_dump( array_merge_recursive($arr1_numeric_key, $arr2) );
27var_dump( array_merge_recursive($arr1_string_key, $arr2) );
28
29echo "Done";
30?>
31--EXPECT--
32*** Testing array_merge_recursive() : array with duplicate keys for $arr1 argument ***
33-- With default argument --
34array(3) {
35  [0]=>
36  array(2) {
37    [0]=>
38    string(9) "duplicate"
39    [1]=>
40    string(7) "strings"
41  }
42  [1]=>
43  array(2) {
44    [0]=>
45    int(1)
46    [1]=>
47    int(2)
48  }
49  [2]=>
50  string(5) "three"
51}
52array(2) {
53  ["str1"]=>
54  string(5) "world"
55  ["str2"]=>
56  float(111.111)
57}
58-- With more arguments --
59array(6) {
60  [0]=>
61  array(2) {
62    [0]=>
63    string(9) "duplicate"
64    [1]=>
65    string(7) "strings"
66  }
67  [1]=>
68  array(2) {
69    [0]=>
70    int(1)
71    [1]=>
72    int(2)
73  }
74  [2]=>
75  string(5) "three"
76  [3]=>
77  string(3) "one"
78  ["str1"]=>
79  string(3) "two"
80  [4]=>
81  array(2) {
82    [0]=>
83    string(3) "one"
84    [1]=>
85    string(3) "two"
86  }
87}
88array(4) {
89  ["str1"]=>
90  array(2) {
91    [0]=>
92    string(5) "world"
93    [1]=>
94    string(3) "two"
95  }
96  ["str2"]=>
97  float(111.111)
98  [0]=>
99  string(3) "one"
100  [1]=>
101  array(2) {
102    [0]=>
103    string(3) "one"
104    [1]=>
105    string(3) "two"
106  }
107}
108Done
109