1--TEST--
2Test array_diff_assoc() function : usage variations - arrays containing referenced variables
3--FILE--
4
5<?php
6/* Prototype  : array array_diff_assoc(array $arr1, array $arr2 [, array ...])
7 * Description: Returns the entries of $arr1 that have values which are not
8 * present in any of the others arguments but do additional checks whether the keys are equal
9 * Source code: ext/standard/array.c
10 */
11
12/*
13 * Tests how array_diff_assoc compares
14 * 1. Referenced variables
15 * 2. Arrays that have been referenced to each other
16 */
17
18echo "*** Testing array_diff_assoc() : usage variations ***\n";
19
20$a = 'a';
21
22$arr1 = array('a', 'b', 'c', $a);
23$arr2 = array('a' => 1, 'b' => 2, 'c' => 3, &$a);
24
25echo "-- Results when \$a = $a: --\n";
26var_dump(array_diff_assoc($arr1, $arr2));
27var_dump(array_diff_assoc($arr2, $arr1));
28
29$a = 4;
30
31echo "-- Results when \$a has been changed to $a: --\n";
32var_dump(array_diff_assoc($arr1, $arr2));
33var_dump(array_diff_assoc($arr2, $arr1));
34
35$arr2 = &$arr1;
36
37echo "-- Results when \$arr2 is referenced to \$arr1 --\n";
38var_dump(array_diff_assoc($arr1, $arr2));
39var_dump(array_diff_assoc($arr2, $arr1));
40
41$arr1 = array('zero' => 'x', 'one' => 'y', 'two' => 'z');
42
43echo "-- Results when \$arr1 is changed --\n";
44var_dump(array_diff_assoc($arr1, $arr2));
45var_dump(array_diff_assoc($arr2, $arr1));
46
47echo "Done";
48?>
49
50--EXPECTF--
51
52*** Testing array_diff_assoc() : usage variations ***
53-- Results when $a = a: --
54array(3) {
55  [1]=>
56  string(1) "b"
57  [2]=>
58  string(1) "c"
59  [3]=>
60  string(1) "a"
61}
62array(3) {
63  ["a"]=>
64  int(1)
65  ["b"]=>
66  int(2)
67  ["c"]=>
68  int(3)
69}
70-- Results when $a has been changed to 4: --
71array(4) {
72  [0]=>
73  string(1) "a"
74  [1]=>
75  string(1) "b"
76  [2]=>
77  string(1) "c"
78  [3]=>
79  string(1) "a"
80}
81array(4) {
82  ["a"]=>
83  int(1)
84  ["b"]=>
85  int(2)
86  ["c"]=>
87  int(3)
88  [0]=>
89  &int(4)
90}
91-- Results when $arr2 is referenced to $arr1 --
92array(0) {
93}
94array(0) {
95}
96-- Results when $arr1 is changed --
97array(0) {
98}
99array(0) {
100}
101Done