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