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