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