1--TEST--
2Test array_intersect_assoc() function : usage variations - different arrays for 'arr2' argument
3--FILE--
4<?php
5/* Prototype  : array array_intersect_assoc(array $arr1, array $arr2 [, array $...])
6 * Description: Returns the entries of arr1 that have values which are present in all the other arguments.
7 * Keys are used to do more restrictive check
8 * Source code: ext/standard/array.c
9*/
10
11/*
12* Passing different types of arrays to $arr2 argument and testing whether
13* array_intersect_assoc() behaves in an expected way with the other arguments passed to the function.
14* The $arr1 argument passed is a fixed array.
15*/
16
17echo "*** Testing array_intersect_assoc() : Passing different types of arrays to \$arr2 argument ***\n";
18
19/* Different heredoc strings passed as argument to $arr2 */
20// heredoc with blank line
21$blank_line = <<<EOT
22
23
24EOT;
25
26// heredoc with multiline string
27$multiline_string = <<<EOT
28hello world
29The big brown fox jumped over;
30the lazy dog
31This is a double quoted string
32EOT;
33
34// heredoc with different whitespaces
35$diff_whitespaces = <<<EOT
36hello\r world\t
371111\t\t != 2222\v\v
38heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces
39EOT;
40
41// heredoc with quoted strings and numeric values
42$numeric_string = <<<EOT
4311 < 12. 123 >22
44'single quoted string'
45"double quoted string"
462222 != 1111.\t 0000 = 0000\n
47EOT;
48
49// array to be passsed to $arr1 argument
50$arr1 = array (
51  1, 1.1, 1.3, 1 => true, "hello", "one", NULL, 2,
52  'world', true, false, 3 => "b\tbbb", "aaaa\r",
53  $numeric_string, "h3" => $diff_whitespaces, "true" => true,
54  "one" => "ten", 4 => "four", "two" => 2, 6 => "six",
55  '', null => "null", '' => 'emptys'
56);
57
58// arrays to be passed to $arr2 argument
59$arrays = array (
60/*1*/  array(1, 2), // array with default keys and numeric values
61       array(1.1, 1.2, 1.3), // array with default keys & float values
62       array(false,true), // array with default keys and boolean values
63       array(), // empty array
64/*5*/  array(NULL), // array with NULL
65       array("a\v\f","aaaa\r","b","b\tbbb","c","\[\]\!\@\#\$\%\^\&\*\(\)\{\}"),  // array with double quoted strings
66       array('a\v\f','aaaa\r','b','b\tbbb','c','\[\]\!\@\#\$\%\^\&\*\(\)\{\}'),  // array with single quoted strings
67       array($blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $numeric_string),  // array with heredocs
68
69       // associative arrays
70/*9*/  array(1 => "one", 2 => "two", 6 => "six"),  // explicit numeric keys, string values
71       array("one" => 1, "two" => 2, "three" => 3 ),  // string keys & numeric values
72       array( 1 => 10, 2 => 20, 4 => 40, 3 => 30),  // explicit numeric keys and numeric values
73       array( "one" => "ten", "two" => "twenty", "three" => "thirty"),  // string key/value
74       array("one" => 1, 2 => "two", 4 => "four"),  //mixed
75
76       // associative array, containing null/empty/boolean values as key/value
77/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null),
78       array(true => "true", false => "false", "false" => false, "true" => true),
79       array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''),
80       array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true),
81       array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6),
82
83       // array with repetative keys
84/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3)
85);
86
87// loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc()
88$iterator = 1;
89foreach($arrays as $arr2) {
90  echo "-- Iteration $iterator --\n";
91
92  // Calling array_intersect_assoc() with default arguments
93  var_dump( array_intersect_assoc($arr1, $arr2) );
94
95  // Calling array_intersect_assoc() with more arguments
96  // additional argument passed is the same as $arr1 argument
97  var_dump( array_intersect_assoc($arr1, $arr2, $arr1) );
98  $iterator++;
99}
100
101echo "Done";
102?>
103--EXPECT--
104*** Testing array_intersect_assoc() : Passing different types of arrays to $arr2 argument ***
105-- Iteration 1 --
106array(1) {
107  [0]=>
108  int(1)
109}
110array(1) {
111  [0]=>
112  int(1)
113}
114-- Iteration 2 --
115array(1) {
116  [2]=>
117  float(1.3)
118}
119array(1) {
120  [2]=>
121  float(1.3)
122}
123-- Iteration 3 --
124array(1) {
125  [1]=>
126  bool(true)
127}
128array(1) {
129  [1]=>
130  bool(true)
131}
132-- Iteration 4 --
133array(0) {
134}
135array(0) {
136}
137-- Iteration 5 --
138array(0) {
139}
140array(0) {
141}
142-- Iteration 6 --
143array(1) {
144  [3]=>
145  string(5) "b	bbb"
146}
147array(1) {
148  [3]=>
149  string(5) "b	bbb"
150}
151-- Iteration 7 --
152array(0) {
153}
154array(0) {
155}
156-- Iteration 8 --
157array(1) {
158  ["h3"]=>
159  string(88) "hello
159 world
1601111		 != 2222
161heredoc
162double quoted string. withdifferentwhitespaces"
163}
164array(1) {
165  ["h3"]=>
166  string(88) "hello
166 world
1671111		 != 2222
168heredoc
169double quoted string. withdifferentwhitespaces"
170}
171-- Iteration 9 --
172array(1) {
173  [6]=>
174  string(3) "six"
175}
176array(1) {
177  [6]=>
178  string(3) "six"
179}
180-- Iteration 10 --
181array(1) {
182  ["two"]=>
183  int(2)
184}
185array(1) {
186  ["two"]=>
187  int(2)
188}
189-- Iteration 11 --
190array(0) {
191}
192array(0) {
193}
194-- Iteration 12 --
195array(1) {
196  ["one"]=>
197  string(3) "ten"
198}
199array(1) {
200  ["one"]=>
201  string(3) "ten"
202}
203-- Iteration 13 --
204array(1) {
205  [4]=>
206  string(4) "four"
207}
208array(1) {
209  [4]=>
210  string(4) "four"
211}
212-- Iteration 14 --
213array(0) {
214}
215array(0) {
216}
217-- Iteration 15 --
218array(1) {
219  ["true"]=>
220  bool(true)
221}
222array(1) {
223  ["true"]=>
224  bool(true)
225}
226-- Iteration 16 --
227array(1) {
228  [""]=>
229  string(6) "emptys"
230}
231array(1) {
232  [""]=>
233  string(6) "emptys"
234}
235-- Iteration 17 --
236array(1) {
237  [5]=>
238  NULL
239}
240array(1) {
241  [5]=>
242  NULL
243}
244-- Iteration 18 --
245array(0) {
246}
247array(0) {
248}
249-- Iteration 19 --
250array(0) {
251}
252array(0) {
253}
254Done
255