1--TEST--
2Test array_intersect_assoc() 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_assoc() behaves in an expected way with the other arguments passed to the function
8* The $arr2 argument passed is a fixed array.
9*/
10
11echo "*** Testing array_intersect_assoc() : 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), // with default keys and numeric values
46       array(1.1, 2.2), // with default keys & float values
47       array(false,true), // with default keys and boolean values
48       array(), // empty array
49/*5*/  array(NULL), // with NULL
50       array("a\v\f","aaaa\r","b","b\tbbb","c","\[\]\!\@\#\$\%\^\&\*\(\)\{\}"),  // with double quoted strings
51       array('a\v\f','aaaa\r','b','b\tbbb','c','\[\]\!\@\#\$\%\^\&\*\(\)\{\}'),  // with single quoted strings
52       array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $numeric_string),  // 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, 2.2, "hello", "one", NULL, 2,
76  'world', true,5 => false, 1 => 'aaaa\r', "aaaa\r",
77  'h3' => $diff_whitespaces, $numeric_string,
78  "one" => "ten", 4 => "four", "two" => 2,
79  '', null => "null", '' => 'emptys', "emptyd" => "",
80);
81
82// loop through each sub-array within $arrays to check the behavior of array_intersect_assoc()
83$iterator = 1;
84foreach($arrays as $arr1) {
85  echo "-- Iteration $iterator --\n";
86
87  // Calling array_intersect_assoc() with default arguments
88  var_dump( array_intersect_assoc($arr1, $arr2) );
89
90  // Calling array_intersect_assoc() with more arguments.
91  // additional argument passed is the same as $arr1 argument
92  var_dump( array_intersect_assoc($arr1, $arr2, $arr1) );
93  $iterator++;
94}
95
96echo "Done";
97?>
98--EXPECT--
99*** Testing array_intersect_assoc() : Passing different types of arrays to $arr1 argument ***
100-- Iteration 1 --
101array(1) {
102  [0]=>
103  int(1)
104}
105array(1) {
106  [0]=>
107  int(1)
108}
109-- Iteration 2 --
110array(0) {
111}
112array(0) {
113}
114-- Iteration 3 --
115array(0) {
116}
117array(0) {
118}
119-- Iteration 4 --
120array(0) {
121}
122array(0) {
123}
124-- Iteration 5 --
125array(0) {
126}
127array(0) {
128}
129-- Iteration 6 --
130array(0) {
131}
132array(0) {
133}
134-- Iteration 7 --
135array(1) {
136  [1]=>
137  string(6) "aaaa\r"
138}
139array(1) {
140  [1]=>
141  string(6) "aaaa\r"
142}
143-- Iteration 8 --
144array(1) {
145  ["h3"]=>
146  string(88) "hello
146 world
1471111		 != 2222
148heredoc
149double quoted string. withdifferentwhitespaces"
150}
151array(1) {
152  ["h3"]=>
153  string(88) "hello
153 world
1541111		 != 2222
155heredoc
156double quoted string. withdifferentwhitespaces"
157}
158-- Iteration 9 --
159array(0) {
160}
161array(0) {
162}
163-- Iteration 10 --
164array(1) {
165  ["two"]=>
166  int(2)
167}
168array(1) {
169  ["two"]=>
170  int(2)
171}
172-- Iteration 11 --
173array(0) {
174}
175array(0) {
176}
177-- Iteration 12 --
178array(1) {
179  ["one"]=>
180  string(3) "ten"
181}
182array(1) {
183  ["one"]=>
184  string(3) "ten"
185}
186-- Iteration 13 --
187array(1) {
188  [4]=>
189  string(4) "four"
190}
191array(1) {
192  [4]=>
193  string(4) "four"
194}
195-- Iteration 14 --
196array(0) {
197}
198array(0) {
199}
200-- Iteration 15 --
201array(0) {
202}
203array(0) {
204}
205-- Iteration 16 --
206array(2) {
207  [""]=>
208  string(6) "emptys"
209  ["emptyd"]=>
210  string(0) ""
211}
212array(2) {
213  [""]=>
214  string(6) "emptys"
215  ["emptyd"]=>
216  string(0) ""
217}
218-- Iteration 17 --
219array(1) {
220  [5]=>
221  bool(false)
222}
223array(1) {
224  [5]=>
225  bool(false)
226}
227-- Iteration 18 --
228array(0) {
229}
230array(0) {
231}
232-- Iteration 19 --
233array(0) {
234}
235array(0) {
236}
237Done
238