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