1--TEST--
2Test array_intersect_assoc() function : usage variations - assoc array with diff values for 'arr1' argument
3--FILE--
4<?php
5/*
6 * Testing the functionality of array_intersect_assoc() by passing different
7 * associative arrays having different possible values to $arr1 argument.
8 * The $arr2 argument passed is a fixed array
9*/
10
11echo "*** Testing array_intersect_assoc() : 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.333),
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(0 => "0", 1, "two" => 2, "float" => 2.3333, "f1" => 1.2,
64              "f4" => 33333333.333, 111 => "\tHello", 3 => 'pen\n', '\v\fworld',
65              "heredoc" => "Hello world", 11 => new classA(), "resource" => $fp,
66              "int" => 133, 222 => "fruit");
67
68// loop through each sub-array within $arrays to check the behavior of array_intersect_assoc()
69$iterator = 1;
70foreach($arrays as $arr1) {
71  echo "-- Iteration $iterator --\n";
72
73  // Calling array_intersect_assoc() with default arguments
74  var_dump( array_intersect_assoc($arr1, $arr2) );
75
76  // Calling array_intersect_assoc() with more arguments.
77  // additional argument passed is the same as $arr1 argument
78  var_dump( array_intersect_assoc($arr1, $arr2, $arr1) );
79  $iterator++;
80}
81
82// close the file resource used
83fclose($fp);
84
85echo "Done";
86?>
87--EXPECTF--
88*** Testing array_intersect_assoc() : assoc array with diff values to $arr1 argument ***
89-- Iteration 1 --
90array(0) {
91}
92array(0) {
93}
94-- Iteration 2 --
95array(1) {
96  [0]=>
97  int(0)
98}
99array(1) {
100  [0]=>
101  int(0)
102}
103-- Iteration 3 --
104array(1) {
105  [1]=>
106  int(1)
107}
108array(1) {
109  [1]=>
110  int(1)
111}
112-- Iteration 4 --
113array(1) {
114  ["two"]=>
115  int(2)
116}
117array(1) {
118  ["two"]=>
119  int(2)
120}
121-- Iteration 5 --
122array(1) {
123  ["float"]=>
124  float(2.3333)
125}
126array(1) {
127  ["float"]=>
128  float(2.3333)
129}
130-- Iteration 6 --
131array(2) {
132  ["f1"]=>
133  float(1.2)
134  ["f4"]=>
135  float(33333333.333)
136}
137array(2) {
138  ["f1"]=>
139  float(1.2)
140  ["f4"]=>
141  float(33333333.333)
142}
143-- Iteration 7 --
144array(1) {
145  [111]=>
146  string(6) "	Hello"
147}
148array(1) {
149  [111]=>
150  string(6) "	Hello"
151}
152-- Iteration 8 --
153array(1) {
154  [3]=>
155  string(5) "pen\n"
156}
157array(1) {
158  [3]=>
159  string(5) "pen\n"
160}
161-- Iteration 9 --
162array(1) {
163  ["heredoc"]=>
164  string(11) "Hello world"
165}
166array(1) {
167  ["heredoc"]=>
168  string(11) "Hello world"
169}
170-- Iteration 10 --
171array(2) {
172  [11]=>
173  object(classA)#%d (0) {
174  }
175  ["resource"]=>
176  resource(%d) of type (stream)
177}
178array(2) {
179  [11]=>
180  object(classA)#%d (0) {
181  }
182  ["resource"]=>
183  resource(%d) of type (stream)
184}
185-- Iteration 11 --
186array(4) {
187  [222]=>
188  string(5) "fruit"
189  ["resource"]=>
190  resource(%d) of type (stream)
191  ["int"]=>
192  int(133)
193  ["heredoc"]=>
194  string(11) "Hello world"
195}
196array(4) {
197  [222]=>
198  string(5) "fruit"
199  ["resource"]=>
200  resource(%d) of type (stream)
201  ["int"]=>
202  int(133)
203  ["heredoc"]=>
204  string(11) "Hello world"
205}
206Done
207