1--TEST--
2Test array_merge() function : usage variations - referenced variables
3--FILE--
4<?php
5/* Test array_merge() when:
6 * 1. Passed an array made up of referenced variables
7 * 2. Passed an array as the first argument and a reference to that array as the second.
8 */
9
10echo "*** Testing array_merge() : usage variations ***\n";
11
12$val1 = 'foo';
13$val2 = 'bar';
14$val3 = 'baz';
15
16$arr1 = array(&$val1, &$val2, &$val3);
17$arr2 = array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3');
18
19echo "\n-- Merge an array made up of referenced variables to an assoc. array --\n";
20var_dump(array_merge($arr1, $arr2));
21var_dump(array_merge($arr2, $arr1));
22
23$val2 = 'hello world';
24
25echo "\n-- Change \$val2 --\n";
26var_dump(array_merge($arr1, $arr2));
27var_dump(array_merge($arr2, $arr1));
28
29echo "Done";
30?>
31--EXPECT--
32*** Testing array_merge() : usage variations ***
33
34-- Merge an array made up of referenced variables to an assoc. array --
35array(6) {
36  [0]=>
37  &string(3) "foo"
38  [1]=>
39  &string(3) "bar"
40  [2]=>
41  &string(3) "baz"
42  ["key1"]=>
43  string(4) "val1"
44  ["key2"]=>
45  string(4) "val2"
46  ["key3"]=>
47  string(4) "val3"
48}
49array(6) {
50  ["key1"]=>
51  string(4) "val1"
52  ["key2"]=>
53  string(4) "val2"
54  ["key3"]=>
55  string(4) "val3"
56  [0]=>
57  &string(3) "foo"
58  [1]=>
59  &string(3) "bar"
60  [2]=>
61  &string(3) "baz"
62}
63
64-- Change $val2 --
65array(6) {
66  [0]=>
67  &string(3) "foo"
68  [1]=>
69  &string(11) "hello world"
70  [2]=>
71  &string(3) "baz"
72  ["key1"]=>
73  string(4) "val1"
74  ["key2"]=>
75  string(4) "val2"
76  ["key3"]=>
77  string(4) "val3"
78}
79array(6) {
80  ["key1"]=>
81  string(4) "val1"
82  ["key2"]=>
83  string(4) "val2"
84  ["key3"]=>
85  string(4) "val3"
86  [0]=>
87  &string(3) "foo"
88  [1]=>
89  &string(11) "hello world"
90  [2]=>
91  &string(3) "baz"
92}
93Done
94