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