1--TEST--
2Test array_intersect() function : usage variations - different arrays for 'arr2' argument
3--FILE--
4<?php
5/*
6* Passing different types of arrays to $arr2 argument and testing whether
7* array_intersect() behaves in expected way with the other arguments passed to the function.
8* The $arr1 argument is a fixed array.
9*/
10
11echo "*** Testing array_intersect() : Passing different types of arrays to \$arr2 argument ***\n";
12
13/* Different heredoc strings passed as argument to $arr2 */
14// heredoc with blank line
15$blank_line = <<<EOT
16
17
18EOT;
19
20// heredoc with multiline string
21$multiline_string = <<<EOT
22hello world
23The big brown fox jumped over;
24the lazy dog
25This is a double quoted string
26EOT;
27
28// heredoc with different whitespaces
29$diff_whitespaces = <<<EOT
30hello\r world\t
311111\t\t != 2222\v\v
32heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces
33EOT;
34
35// heredoc with quoted strings and numeric values
36$numeric_string = <<<EOT
3711 < 12. 123 >22
38'single quoted string'
39"double quoted string"
402222 != 1111.\t 0000 = 0000\n
41EOT;
42
43// array to be passsed to $arr1 argument
44$arr1 = array (
45  1, 1.1, "hello", "one", NULL, 2,
46  'world', true, false, false => 5, 'aaaa\r', "aaaa\r",
47  $numeric_string, $diff_whitespaces,
48  "one" => "ten", 4 => "four", "two" => 2, 2 => "two",
49  '', null => "null", '' => 'emptys'
50);
51
52// arrays to be passed to $arr2 argument
53$arrays = array (
54/*1*/  array(1, 2), // array with default keys and numeric values
55       array(1.1, 2.2), // array with default keys & float values
56       array(false,true), // array with default keys and boolean values
57       array(), // empty array
58/*5*/  array(NULL), // array with NULL
59       array("a\v\f","aaaa\r","b","b\tbbb","c","\[\]\!\@\#\$\%\^\&\*\(\)\{\}"),  // array with double quoted strings
60       array('a\v\f','aaaa\r','b','b\tbbb','c','\[\]\!\@\#\$\%\^\&\*\(\)\{\}'),  // array with single quoted strings
61       array($blank_line, $multiline_string, $diff_whitespaces, $numeric_string),  // array with heredocs
62
63       // associative arrays
64/*9*/  array(1 => "one", 2 => "two", 3 => "three"),  // explicit numeric keys, string values
65       array("one" => 1, "two" => 2, "three" => 3 ),  // string keys & numeric values
66       array( 1 => 10, 2 => 20, 4 => 40, 3 => 30),  // explicit numeric keys and numeric values
67       array( "one" => "ten", "two" => "twenty", "three" => "thirty"),  // string key/value
68       array("one" => 1, 2 => "two", 4 => "four"),  //mixed
69
70       // associative array, containing null/empty/boolean values as key/value
71/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null),
72       array(true => "true", false => "false", "false" => false, "true" => true),
73       array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''),
74       array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true),
75       array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6),
76
77       // array with repetitive keys
78/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3)
79);
80
81// loop through each sub-array within $arrays to check the behavior of array_intersect()
82$iterator = 1;
83foreach($arrays as $arr2) {
84  echo "-- Iteration $iterator --\n";
85
86  // Calling array_intersect() with default arguments
87  var_dump( array_intersect($arr1, $arr2) );
88
89  // Calling array_intersect() with more arguments
90  // additional argument passed is the same as $arr1 argument
91  var_dump( array_intersect($arr1, $arr2, $arr1) );
92  $iterator++;
93}
94
95echo "Done";
96?>
97--EXPECT--
98*** Testing array_intersect() : Passing different types of arrays to $arr2 argument ***
99-- Iteration 1 --
100array(3) {
101  [5]=>
102  int(2)
103  [7]=>
104  bool(true)
105  ["two"]=>
106  int(2)
107}
108array(3) {
109  [5]=>
110  int(2)
111  [7]=>
112  bool(true)
113  ["two"]=>
114  int(2)
115}
116-- Iteration 2 --
117array(1) {
118  [1]=>
119  float(1.1)
120}
121array(1) {
122  [1]=>
123  float(1.1)
124}
125-- Iteration 3 --
126array(3) {
127  [7]=>
128  bool(true)
129  [8]=>
130  bool(false)
131  [13]=>
132  string(0) ""
133}
134array(3) {
135  [7]=>
136  bool(true)
137  [8]=>
138  bool(false)
139  [13]=>
140  string(0) ""
141}
142-- Iteration 4 --
143array(0) {
144}
145array(0) {
146}
147-- Iteration 5 --
148array(2) {
149  [8]=>
150  bool(false)
151  [13]=>
152  string(0) ""
153}
154array(2) {
155  [8]=>
156  bool(false)
157  [13]=>
158  string(0) ""
159}
160-- Iteration 6 --
161array(1) {
162  [10]=>
163  string(5) "aaaa
163"
164}
165array(1) {
166  [10]=>
167  string(5) "aaaa
167"
168}
169-- Iteration 7 --
170array(1) {
171  [9]=>
172  string(6) "aaaa\r"
173}
174array(1) {
175  [9]=>
176  string(6) "aaaa\r"
177}
178-- Iteration 8 --
179array(2) {
180  [11]=>
181  string(90) "11 < 12. 123 >22
182'single quoted string'
183"double quoted string"
1842222 != 1111.	 0000 = 0000
185"
186  [12]=>
187  string(88) "hello
187 world
1881111		 != 2222
189heredoc
190double quoted string. withdifferentwhitespaces"
191}
192array(2) {
193  [11]=>
194  string(90) "11 < 12. 123 >22
195'single quoted string'
196"double quoted string"
1972222 != 1111.	 0000 = 0000
198"
199  [12]=>
200  string(88) "hello
200 world
2011111		 != 2222
202heredoc
203double quoted string. withdifferentwhitespaces"
204}
205-- Iteration 9 --
206array(2) {
207  [2]=>
208  string(3) "two"
209  [3]=>
210  string(3) "one"
211}
212array(2) {
213  [2]=>
214  string(3) "two"
215  [3]=>
216  string(3) "one"
217}
218-- Iteration 10 --
219array(3) {
220  [5]=>
221  int(2)
222  [7]=>
223  bool(true)
224  ["two"]=>
225  int(2)
226}
227array(3) {
228  [5]=>
229  int(2)
230  [7]=>
231  bool(true)
232  ["two"]=>
233  int(2)
234}
235-- Iteration 11 --
236array(0) {
237}
238array(0) {
239}
240-- Iteration 12 --
241array(1) {
242  ["one"]=>
243  string(3) "ten"
244}
245array(1) {
246  ["one"]=>
247  string(3) "ten"
248}
249-- Iteration 13 --
250array(3) {
251  [2]=>
252  string(3) "two"
253  [4]=>
254  string(4) "four"
255  [7]=>
256  bool(true)
257}
258array(3) {
259  [2]=>
260  string(3) "two"
261  [4]=>
262  string(4) "four"
263  [7]=>
264  bool(true)
265}
266-- Iteration 14 --
267array(2) {
268  [8]=>
269  bool(false)
270  [13]=>
271  string(0) ""
272}
273array(2) {
274  [8]=>
275  bool(false)
276  [13]=>
277  string(0) ""
278}
279-- Iteration 15 --
280array(3) {
281  [7]=>
282  bool(true)
283  [8]=>
284  bool(false)
285  [13]=>
286  string(0) ""
287}
288array(3) {
289  [7]=>
290  bool(true)
291  [8]=>
292  bool(false)
293  [13]=>
294  string(0) ""
295}
296-- Iteration 16 --
297array(3) {
298  [8]=>
299  bool(false)
300  [13]=>
301  string(0) ""
302  [""]=>
303  string(6) "emptys"
304}
305array(3) {
306  [8]=>
307  bool(false)
308  [13]=>
309  string(0) ""
310  [""]=>
311  string(6) "emptys"
312}
313-- Iteration 17 --
314array(3) {
315  [7]=>
316  bool(true)
317  [8]=>
318  bool(false)
319  [13]=>
320  string(0) ""
321}
322array(3) {
323  [7]=>
324  bool(true)
325  [8]=>
326  bool(false)
327  [13]=>
328  string(0) ""
329}
330-- Iteration 18 --
331array(1) {
332  [0]=>
333  int(5)
334}
335array(1) {
336  [0]=>
337  int(5)
338}
339-- Iteration 19 --
340array(0) {
341}
342array(0) {
343}
344Done
345