1--TEST--
2Test array_intersect() function : usage variations - assoc array with diff keys for 'arr2' argument
3--FILE--
4<?php
5/*
6 * Testing the functionality of array_intersect() by passing different
7 * associative arrays having different possible keys to $arr2 argument.
8 * The $arr1 argument is a fixed array.
9*/
10
11echo "*** Testing array_intersect() : assoc array with diff keys to \$arr2 argument ***\n";
12
13// get an unset variable
14$unset_var = 10;
15unset ($unset_var);
16
17// get a heredoc string
18$heredoc = <<<EOT
19Hello world
20EOT;
21
22// different variations of associative arrays to be passed to $arr2 argument
23$arrays = array (
24
25       // empty array
26/*1*/  array(),
27
28       // arrays with integer keys
29       array(0 => "0"),
30       array(1 => "1"),
31       array(1 => "1", 2 => "2", 3 => "3", 4 => "4"),
32
33       // arrays with float keys
34/*5*/  array(2.3333 => "float"),
35       array(1.2 => "f1", 3.33 => "f2",
36             4.89999922839999 => "f3",
37             33333333.333333 => "f4"),
38
39       // arrays with string keys
40/*7*/  array('\tHello' => 111, 're\td' => "color",
41             '\v\fworld' => 2.2, 'pen\n' => 33),
42       array("\tHello" => 111, "re\td" => "color",
43             "\v\fworld" => 2.2, "pen\n" => 33),
44       array("hello", $heredoc => "string"), // heredoc
45
46       // array with unset variable
47/*10*/ array( @$unset_var => "hello"),
48
49       // array with mixed keys
50/*11*/ array('hello' => 1,  "fruit" => 2.2,
51             133 => "int", 444.432 => "float",
52             @$unset_var => "unset", $heredoc => "heredoc")
53);
54
55// array to be passsed to $arr1 argument
56$arr1 = array(1, "float", "f4", "hello", 2.2, 'color', "string", "pen\n", 11);
57
58// loop through each sub-array within $arrays to check the behavior of array_intersect()
59$iterator = 1;
60foreach($arrays as $arr2) {
61  echo "-- Iterator $iterator --\n";
62
63  // Calling array_intersect() with default arguments
64  var_dump( array_intersect($arr1, $arr2) );
65
66  // Calling array_intersect() with more arguments.
67  // additional argument passed is the same as $arr1 argument
68  var_dump( array_intersect($arr1, $arr2, $arr1) );
69  $iterator++;
70}
71
72echo "Done";
73?>
74--EXPECT--
75*** Testing array_intersect() : assoc array with diff keys to $arr2 argument ***
76-- Iterator 1 --
77array(0) {
78}
79array(0) {
80}
81-- Iterator 2 --
82array(0) {
83}
84array(0) {
85}
86-- Iterator 3 --
87array(1) {
88  [0]=>
89  int(1)
90}
91array(1) {
92  [0]=>
93  int(1)
94}
95-- Iterator 4 --
96array(1) {
97  [0]=>
98  int(1)
99}
100array(1) {
101  [0]=>
102  int(1)
103}
104-- Iterator 5 --
105array(1) {
106  [1]=>
107  string(5) "float"
108}
109array(1) {
110  [1]=>
111  string(5) "float"
112}
113-- Iterator 6 --
114array(1) {
115  [2]=>
116  string(2) "f4"
117}
118array(1) {
119  [2]=>
120  string(2) "f4"
121}
122-- Iterator 7 --
123array(2) {
124  [4]=>
125  float(2.2)
126  [5]=>
127  string(5) "color"
128}
129array(2) {
130  [4]=>
131  float(2.2)
132  [5]=>
133  string(5) "color"
134}
135-- Iterator 8 --
136array(2) {
137  [4]=>
138  float(2.2)
139  [5]=>
140  string(5) "color"
141}
142array(2) {
143  [4]=>
144  float(2.2)
145  [5]=>
146  string(5) "color"
147}
148-- Iterator 9 --
149array(2) {
150  [3]=>
151  string(5) "hello"
152  [6]=>
153  string(6) "string"
154}
155array(2) {
156  [3]=>
157  string(5) "hello"
158  [6]=>
159  string(6) "string"
160}
161-- Iterator 10 --
162array(1) {
163  [3]=>
164  string(5) "hello"
165}
166array(1) {
167  [3]=>
168  string(5) "hello"
169}
170-- Iterator 11 --
171array(3) {
172  [0]=>
173  int(1)
174  [1]=>
175  string(5) "float"
176  [4]=>
177  float(2.2)
178}
179array(3) {
180  [0]=>
181  int(1)
182  [1]=>
183  string(5) "float"
184  [4]=>
185  float(2.2)
186}
187Done
188