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