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