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