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