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