1--TEST--
2Test array_diff() function : usage variations - multidimensional arrays
3--FILE--
4<?php
5/* Prototype  : array array_diff(array $arr1, array $arr2 [, array ...])
6 * Description: Returns the entries of arr1 that have values which are
7 * not present in any of the others arguments.
8 * Source code: ext/standard/array.c
9 */
10
11/*
12 * Test how array_diff() compares multidimensional arrays
13 */
14
15echo "*** Testing array_diff() : usage variations ***\n";
16
17$array1 = array('sub_array1' => array (1, 2, 3),
18                'sub_array2' => array ('a', 'b', 'c'));
19$array2 = array('sub_arraya' => array (1, 3, 5),
20                'sub_arrayb' => array ('a', 'z', 'y'));
21
22echo "-- Compare two 2-D arrays --\n";
23var_dump(array_diff($array1, $array2));
24var_dump(array_diff($array2, $array1));
25
26echo "\n-- Compare subarrays from two 2-D arrays --\n";
27var_dump(array_diff($array1['sub_array1'], $array2['sub_arraya']));
28var_dump(array_diff($array2['sub_arraya'], $array1['sub_array1']));
29
30var_dump(array_diff($array1['sub_array2'], $array2['sub_arrayb']));
31var_dump(array_diff($array2['sub_arrayb'], $array1['sub_array1']));
32
33echo "\n-- Compare a subarray from one 2-D array and one 2-D array --\n";
34var_dump(array_diff($array1['sub_array1'], $array2));
35var_dump(array_diff($array1, $array2['sub_arraya']));
36
37echo "Done";
38?>
39--EXPECTF--
40*** Testing array_diff() : usage variations ***
41-- Compare two 2-D arrays --
42array(0) {
43}
44array(0) {
45}
46
47-- Compare subarrays from two 2-D arrays --
48array(1) {
49  [1]=>
50  int(2)
51}
52array(1) {
53  [2]=>
54  int(5)
55}
56array(2) {
57  [1]=>
58  string(1) "b"
59  [2]=>
60  string(1) "c"
61}
62array(3) {
63  [0]=>
64  string(1) "a"
65  [1]=>
66  string(1) "z"
67  [2]=>
68  string(1) "y"
69}
70
71-- Compare a subarray from one 2-D array and one 2-D array --
72array(3) {
73  [0]=>
74  int(1)
75  [1]=>
76  int(2)
77  [2]=>
78  int(3)
79}
80array(2) {
81  ["sub_array1"]=>
82  array(3) {
83    [0]=>
84    int(1)
85    [1]=>
86    int(2)
87    [2]=>
88    int(3)
89  }
90  ["sub_array2"]=>
91  array(3) {
92    [0]=>
93    string(1) "a"
94    [1]=>
95    string(1) "b"
96    [2]=>
97    string(1) "c"
98  }
99}
100Done