1--TEST--
2Test of the array_intersect_key() and array_intersect_ukey()
3--FILE--
4<?php
5$a = array(1, 6, 2, -20, 15, 1200, -2500);
6$b = array(0, 7, 2, -20, 11, 1100, -2500);
7$c = array(0, 6, 2, -20, 19, 1000, -2500);
8$d = array(3, 8,-2, -20, 14,  900, -2600);
9
10$a_f = array_flip($a);
11$b_f = array_flip($b);
12$c_f = array_flip($c);
13$d_f = array_flip($d);
14
15/* give nicer values */
16foreach ($a_f as $k=> &$a_f_el) { $a_f_el =$k*2;}
17foreach ($b_f as $k=> &$b_f_el) { $b_f_el =$k*2;}
18foreach ($c_f as $k=> &$c_f_el) { $c_f_el =$k*2;}
19foreach ($d_f as $k=> &$d_f_el) { $d_f_el =$k*2;}
20
21var_dump(array_intersect_key($a_f, $b_f));// keys -> 2, -20, -2500
22var_dump(array_intersect_ukey($a_f, $b_f, "comp_func"));// 2, 20, -2500
23var_dump(array_intersect_key($a_f, $c_f));// keys -> 6, 2, -20, -2500
24var_dump(array_intersect_ukey($a_f, $c_f, "comp_func"));// 6, 2, -20, -2500
25var_dump(array_intersect_key($a_f, $d_f));// -20
26var_dump(array_intersect_ukey($a_f, $d_f, "comp_func"));// -20
27
28var_dump(array_intersect_key($a_f, $b_f, $c_f));// 2, -20, -2500
29var_dump(array_intersect_ukey($a_f, $b_f, $c_f, "comp_func"));// 2, -20, -2500
30var_dump(array_intersect_key($a_f, $b_f, $d_f));// -20
31var_dump(array_intersect_ukey($a_f, $b_f, $d_f, "comp_func"));// -20
32
33var_dump(array_intersect_key($a_f, $b_f, $c_f, $d_f));// -20
34var_dump(array_intersect_ukey($a_f, $b_f, $c_f, $d_f, "comp_func"));//-20
35
36
37var_dump(array_intersect_key($b_f, $c_f));// 0, 2, -20, -2500
38var_dump(array_intersect_ukey($b_f, $c_f, "comp_func"));//0, 2, -20, 2500
39
40var_dump(array_intersect_key($b_f, $d_f));// -20
41var_dump(array_intersect_ukey($b_f, $d_f, "comp_func"));// -20
42
43var_dump(array_intersect_key($b_f, $c_f, $d_f));// -20
44var_dump(array_intersect_ukey($b_f, $c_f,  $d_f, "comp_func"));// -20
45
46
47echo "----- Now testing array_intersect() ------- \n";
48var_dump(array_intersect($a, $b_f));
49var_dump(array_uintersect($a, $b, "comp_func"));
50var_dump(array_intersect($a, $b, $c));
51var_dump(array_uintersect($a, $b, $c, "comp_func"));
52var_dump(array_intersect($a, $b, $c, $d));
53var_dump(array_uintersect($a, $b, $c, $d, "comp_func"));
54
55///////////////////////////////////////////////////////////////////////
56function comp_func($a, $b) {
57        if ($a === $b) return 0;
58        return ($a > $b)? 1:-1;
59
60}
61?>
62--EXPECTF--
63array(3) {
64  [2]=>
65  int(4)
66  [-20]=>
67  int(-40)
68  [-2500]=>
69  &int(-5000)
70}
71array(3) {
72  [2]=>
73  int(4)
74  [-20]=>
75  int(-40)
76  [-2500]=>
77  &int(-5000)
78}
79array(4) {
80  [6]=>
81  int(12)
82  [2]=>
83  int(4)
84  [-20]=>
85  int(-40)
86  [-2500]=>
87  &int(-5000)
88}
89array(4) {
90  [6]=>
91  int(12)
92  [2]=>
93  int(4)
94  [-20]=>
95  int(-40)
96  [-2500]=>
97  &int(-5000)
98}
99array(1) {
100  [-20]=>
101  int(-40)
102}
103array(1) {
104  [-20]=>
105  int(-40)
106}
107array(3) {
108  [2]=>
109  int(4)
110  [-20]=>
111  int(-40)
112  [-2500]=>
113  &int(-5000)
114}
115array(3) {
116  [2]=>
117  int(4)
118  [-20]=>
119  int(-40)
120  [-2500]=>
121  &int(-5000)
122}
123array(1) {
124  [-20]=>
125  int(-40)
126}
127array(1) {
128  [-20]=>
129  int(-40)
130}
131array(1) {
132  [-20]=>
133  int(-40)
134}
135array(1) {
136  [-20]=>
137  int(-40)
138}
139array(4) {
140  [0]=>
141  int(0)
142  [2]=>
143  int(4)
144  [-20]=>
145  int(-40)
146  [-2500]=>
147  &int(-5000)
148}
149array(4) {
150  [0]=>
151  int(0)
152  [2]=>
153  int(4)
154  [-20]=>
155  int(-40)
156  [-2500]=>
157  &int(-5000)
158}
159array(1) {
160  [-20]=>
161  int(-40)
162}
163array(1) {
164  [-20]=>
165  int(-40)
166}
167array(1) {
168  [-20]=>
169  int(-40)
170}
171array(1) {
172  [-20]=>
173  int(-40)
174}
175----- Now testing array_intersect() -------
176array(0) {
177}
178array(3) {
179  [2]=>
180  int(2)
181  [3]=>
182  int(-20)
183  [6]=>
184  int(-2500)
185}
186array(3) {
187  [2]=>
188  int(2)
189  [3]=>
190  int(-20)
191  [6]=>
192  int(-2500)
193}
194array(3) {
195  [2]=>
196  int(2)
197  [3]=>
198  int(-20)
199  [6]=>
200  int(-2500)
201}
202array(1) {
203  [3]=>
204  int(-20)
205}
206array(1) {
207  [3]=>
208  int(-20)
209}
210