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