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