1--TEST--
2Test array_intersect_assoc() function : usage variations - assoc array with diff keys 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 keys to $arr1 argument.
8 * The $arr2 argument passed is a fixed array
9*/
10
11echo "*** Testing array_intersect_assoc() : assoc array with diff keys to \$arr1 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 $arr1 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 string keys
34/*7*/  array('\tHello' => 111, 're\td' => "color",
35             '\v\fworld' => 2.2, 'pen\n' => 33),
36       array("\tHello" => 111, "re\td" => "color",
37             "\v\fworld" => 2.2, "pen\n" => 33),
38       array("hello", $heredoc => "string"), // heredoc
39
40       // array with object, unset variable and resource variable
41/*10*/ array(@$unset_var => "hello"),
42
43       // array with mixed keys
44/*11*/ array('hello' => 1, "fruit" => 2.2,
45              133 => "int",
46             @$unset_var => "unset", $heredoc => "heredoc")
47);
48
49// array to be passed to $arr2 argument
50$arr2 = array(0 => 0, 2 => "float", 4 => "f3", 33333333 => "f4",
51              "\tHello" => 111, 2.2, 'color', "Hello world" => "string",
52              "pen\n" => 33,  133 => "int");
53
54// loop through each sub-array within $arrays to check the behavior of array_intersect_assoc()
55$iterator = 1;
56foreach($arrays as $arr1) {
57  echo "-- Iteration $iterator --\n";
58
59  // Calling array_intersect_assoc() with default arguments
60  var_dump( array_intersect_assoc($arr1, $arr2) );
61
62  // Calling array_intersect_assoc() with more arguments.
63  // additional argument passed is the same as $arr1 argument
64  var_dump( array_intersect_assoc($arr1, $arr2, $arr1) );
65  $iterator++;
66}
67
68echo "Done";
69?>
70--EXPECT--
71*** Testing array_intersect_assoc() : assoc array with diff keys to $arr1 argument ***
72-- Iteration 1 --
73array(0) {
74}
75array(0) {
76}
77-- Iteration 2 --
78array(1) {
79  [0]=>
80  string(1) "0"
81}
82array(1) {
83  [0]=>
84  string(1) "0"
85}
86-- Iteration 3 --
87array(0) {
88}
89array(0) {
90}
91-- Iteration 4 --
92array(0) {
93}
94array(0) {
95}
96-- Iteration 5 --
97array(0) {
98}
99array(0) {
100}
101-- Iteration 6 --
102array(2) {
103  ["	Hello"]=>
104  int(111)
105  ["pen
106"]=>
107  int(33)
108}
109array(2) {
110  ["	Hello"]=>
111  int(111)
112  ["pen
113"]=>
114  int(33)
115}
116-- Iteration 7 --
117array(1) {
118  ["Hello world"]=>
119  string(6) "string"
120}
121array(1) {
122  ["Hello world"]=>
123  string(6) "string"
124}
125-- Iteration 8 --
126array(0) {
127}
128array(0) {
129}
130-- Iteration 9 --
131array(1) {
132  [133]=>
133  string(3) "int"
134}
135array(1) {
136  [133]=>
137  string(3) "int"
138}
139Done
140