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