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
160 world
1611111		 != 2222
162heredoc
163double quoted string. withdifferentwhitespaces"
164}
165array(1) {
166  ["h3"]=>
167  string(88) "hello
168 world
1691111		 != 2222
170heredoc
171double quoted string. withdifferentwhitespaces"
172}
173-- Iteration 9 --
174array(1) {
175  [6]=>
176  string(3) "six"
177}
178array(1) {
179  [6]=>
180  string(3) "six"
181}
182-- Iteration 10 --
183array(1) {
184  ["two"]=>
185  int(2)
186}
187array(1) {
188  ["two"]=>
189  int(2)
190}
191-- Iteration 11 --
192array(0) {
193}
194array(0) {
195}
196-- Iteration 12 --
197array(1) {
198  ["one"]=>
199  string(3) "ten"
200}
201array(1) {
202  ["one"]=>
203  string(3) "ten"
204}
205-- Iteration 13 --
206array(1) {
207  [4]=>
208  string(4) "four"
209}
210array(1) {
211  [4]=>
212  string(4) "four"
213}
214-- Iteration 14 --
215array(0) {
216}
217array(0) {
218}
219-- Iteration 15 --
220array(1) {
221  ["true"]=>
222  bool(true)
223}
224array(1) {
225  ["true"]=>
226  bool(true)
227}
228-- Iteration 16 --
229array(1) {
230  [""]=>
231  string(6) "emptys"
232}
233array(1) {
234  [""]=>
235  string(6) "emptys"
236}
237-- Iteration 17 --
238array(1) {
239  [5]=>
240  NULL
241}
242array(1) {
243  [5]=>
244  NULL
245}
246-- Iteration 18 --
247array(0) {
248}
249array(0) {
250}
251-- Iteration 19 --
252array(0) {
253}
254array(0) {
255}
256Done
257