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
|
--TEST--
Test array_diff_assoc() function : usage variations - arrays containing referenced variables
--FILE--
<?php
/*
* Tests how array_diff_assoc compares
* 1. Referenced variables
* 2. Arrays that have been referenced to each other
*/
echo "*** Testing array_diff_assoc() : usage variations ***\n";
$a = 'a';
$arr1 = array('a', 'b', 'c', $a);
$arr2 = array('a' => 1, 'b' => 2, 'c' => 3, &$a);
echo "-- Results when \$a = $a: --\n";
var_dump(array_diff_assoc($arr1, $arr2));
var_dump(array_diff_assoc($arr2, $arr1));
$a = 4;
echo "-- Results when \$a has been changed to $a: --\n";
var_dump(array_diff_assoc($arr1, $arr2));
var_dump(array_diff_assoc($arr2, $arr1));
$arr2 = &$arr1;
echo "-- Results when \$arr2 is referenced to \$arr1 --\n";
var_dump(array_diff_assoc($arr1, $arr2));
var_dump(array_diff_assoc($arr2, $arr1));
$arr1 = array('zero' => 'x', 'one' => 'y', 'two' => 'z');
echo "-- Results when \$arr1 is changed --\n";
var_dump(array_diff_assoc($arr1, $arr2));
var_dump(array_diff_assoc($arr2, $arr1));
echo "Done";
?>
--EXPECT--
*** Testing array_diff_assoc() : usage variations ***
-- Results when $a = a: --
array(3) {
[1]=>
string(1) "b"
[2]=>
string(1) "c"
[3]=>
string(1) "a"
}
array(3) {
["a"]=>
int(1)
["b"]=>
int(2)
["c"]=>
int(3)
}
-- Results when $a has been changed to 4: --
array(4) {
[0]=>
string(1) "a"
[1]=>
string(1) "b"
[2]=>
string(1) "c"
[3]=>
string(1) "a"
}
array(4) {
["a"]=>
int(1)
["b"]=>
int(2)
["c"]=>
int(3)
[0]=>
&int(4)
}
-- Results when $arr2 is referenced to $arr1 --
array(0) {
}
array(0) {
}
-- Results when $arr1 is changed --
array(0) {
}
array(0) {
}
Done
|