xref: /PHP-7.4/ext/standard/tests/array/bug20381.phpt (revision ac209557)
1--TEST--
2Bug #20381 (array_merge_recursive mangles input arrays)
3--FILE--
4<?php
5$a = array(
6	'a1' => 1,
7	'a2' => array( 1, 2, 3 ),
8	'a3' => array(
9		'a' => array( 10, 20, 30 ),
10		'b' => 'b'
11		)
12	);
13$b = array( 'a1' => 2,
14	'a2' => array( 3, 4, 5 ),
15	'a3' => array(
16		'c' => 'cc',
17		'a' => array( 10, 40 )
18		)
19	);
20
21var_dump($a);
22array_merge_recursive( $a, $b );
23var_dump($a);
24?>
25--EXPECT--
26array(3) {
27  ["a1"]=>
28  int(1)
29  ["a2"]=>
30  array(3) {
31    [0]=>
32    int(1)
33    [1]=>
34    int(2)
35    [2]=>
36    int(3)
37  }
38  ["a3"]=>
39  array(2) {
40    ["a"]=>
41    array(3) {
42      [0]=>
43      int(10)
44      [1]=>
45      int(20)
46      [2]=>
47      int(30)
48    }
49    ["b"]=>
50    string(1) "b"
51  }
52}
53array(3) {
54  ["a1"]=>
55  int(1)
56  ["a2"]=>
57  array(3) {
58    [0]=>
59    int(1)
60    [1]=>
61    int(2)
62    [2]=>
63    int(3)
64  }
65  ["a3"]=>
66  array(2) {
67    ["a"]=>
68    array(3) {
69      [0]=>
70      int(10)
71      [1]=>
72      int(20)
73      [2]=>
74      int(30)
75    }
76    ["b"]=>
77    string(1) "b"
78  }
79}
80