1--TEST--
2Test array_intersect() function : usage variations - two dimensional arrays for $arr1 and $arr2 arguments(Bug#43109)
3--FILE--
4<?php
5/* Prototype  : array array_intersect(array $arr1, array $arr2 [, array $...])
6 * Description: Returns the entries of arr1 that have values which are present in all the other arguments
7 * Source code: ext/standard/array.c
8*/
9
10/*
11* Testing the behavior of array_intersect() by passing 2-D arrays
12* to both $arr1 and $arr2 argument.
13* Optional argument takes the same value as that of $arr1
14*/
15
16echo "*** Testing array_intersect() : passing two dimensional array to both \$arr1 and \$arr2 arguments ***\n";
17
18// two dimensional arrays for $arr1 and $arr2 argument
19$arr1 = array (
20
21  // arrays with default keys
22  array(1, 2, "hello", 'world'),
23  array(1, 2, 3, 4),
24
25  // arrays with explicit keys
26  array(1 => "one", 2 => "two", 3 => "three"),
27  array("ten" => 10, "twenty" => 20.00, "thirty" => 30)
28);
29
30$arr2 = array (
31  array(1, 2, 3, 4),
32  array(1 => "one", 2 => "two", 3 => "three")
33);
34
35/* Passing the entire array as argument to $arr1 and $arr2 */
36// Calling array_intersect() with default arguments
37echo "-- Passing the entire 2-D array to \$arr1 and \$arr2 --\n";
38echo "- With default arguments -\n";
39var_dump( array_intersect($arr1, $arr2) );
40
41// Calling array_intersect() with more arguments
42// additional argument passed is the same as $arr1
43echo "- With more arguments -\n";
44var_dump( array_intersect($arr1, $arr2, $arr1) );
45
46/* Passing the sub-array as argument to $arr1 and $arr2 */
47// Calling array_intersect() with default arguments
48echo "-- Passing the sub-array to \$arr1 and \$arr2 --\n";
49echo "- With default arguments -\n";
50var_dump( array_intersect($arr1[0], $arr2[0]) );
51
52// Calling array_intersect() with more arguments
53// additional argument passed is the same as $arr1
54echo "- With more arguments -\n";
55var_dump( array_intersect($arr1[0], $arr2[0], $arr1[0]) );
56
57echo "Done";
58?>
59--EXPECTF--
60*** Testing array_intersect() : passing two dimensional array to both $arr1 and $arr2 arguments ***
61-- Passing the entire 2-D array to $arr1 and $arr2 --
62- With default arguments -
63array(4) {
64  [0]=>
65  array(4) {
66    [0]=>
67    int(1)
68    [1]=>
69    int(2)
70    [2]=>
71    string(5) "hello"
72    [3]=>
73    string(5) "world"
74  }
75  [1]=>
76  array(4) {
77    [0]=>
78    int(1)
79    [1]=>
80    int(2)
81    [2]=>
82    int(3)
83    [3]=>
84    int(4)
85  }
86  [2]=>
87  array(3) {
88    [1]=>
89    string(3) "one"
90    [2]=>
91    string(3) "two"
92    [3]=>
93    string(5) "three"
94  }
95  [3]=>
96  array(3) {
97    ["ten"]=>
98    int(10)
99    ["twenty"]=>
100    float(20)
101    ["thirty"]=>
102    int(30)
103  }
104}
105- With more arguments -
106array(4) {
107  [0]=>
108  array(4) {
109    [0]=>
110    int(1)
111    [1]=>
112    int(2)
113    [2]=>
114    string(5) "hello"
115    [3]=>
116    string(5) "world"
117  }
118  [1]=>
119  array(4) {
120    [0]=>
121    int(1)
122    [1]=>
123    int(2)
124    [2]=>
125    int(3)
126    [3]=>
127    int(4)
128  }
129  [2]=>
130  array(3) {
131    [1]=>
132    string(3) "one"
133    [2]=>
134    string(3) "two"
135    [3]=>
136    string(5) "three"
137  }
138  [3]=>
139  array(3) {
140    ["ten"]=>
141    int(10)
142    ["twenty"]=>
143    float(20)
144    ["thirty"]=>
145    int(30)
146  }
147}
148-- Passing the sub-array to $arr1 and $arr2 --
149- With default arguments -
150array(2) {
151  [0]=>
152  int(1)
153  [1]=>
154  int(2)
155}
156- With more arguments -
157array(2) {
158  [0]=>
159  int(1)
160  [1]=>
161  int(2)
162}
163Done
164