1--TEST--
2Test array_intersect() function : basic functionality
3--FILE--
4<?php
5/*
6* Testing the behavior of array_intersect() by passing different arrays for the arguments.
7* Function is tested by passing associative array as well as array with default keys.
8*/
9
10echo "*** Testing array_intersect() : basic functionality ***\n";
11
12// array with default keys
13$arr_default_keys = array(1, 2, "hello", 'world');
14
15// associative array
16$arr_associative = array("one" => 1, "two" => 2);
17
18// default key array for both $arr1 and $arr2 argument
19var_dump( array_intersect($arr_default_keys, $arr_default_keys) );
20
21// default key array for $arr1 and associative array for $arr2 argument
22var_dump( array_intersect($arr_default_keys, $arr_associative) );
23
24// associative array for $arr1 and default key array for $arr2
25var_dump( array_intersect($arr_associative, $arr_default_keys) );
26
27// associative array for both $arr1 and $arr2 argument
28var_dump( array_intersect($arr_associative, $arr_associative) );
29
30// more arrays to be intersected
31$arr3 = array(2, 3, 4);
32var_dump( array_intersect($arr_default_keys, $arr_associative, $arr3) );
33var_dump( array_intersect($arr_associative, $arr_default_keys, $arr3, $arr_associative) );
34
35echo "Done";
36?>
37--EXPECT--
38*** Testing array_intersect() : basic functionality ***
39array(4) {
40  [0]=>
41  int(1)
42  [1]=>
43  int(2)
44  [2]=>
45  string(5) "hello"
46  [3]=>
47  string(5) "world"
48}
49array(2) {
50  [0]=>
51  int(1)
52  [1]=>
53  int(2)
54}
55array(2) {
56  ["one"]=>
57  int(1)
58  ["two"]=>
59  int(2)
60}
61array(2) {
62  ["one"]=>
63  int(1)
64  ["two"]=>
65  int(2)
66}
67array(1) {
68  [1]=>
69  int(2)
70}
71array(1) {
72  ["two"]=>
73  int(2)
74}
75Done
76