1--TEST--
2Test array_diff() function : usage variations - multidimensional arrays
3--FILE--
4<?php
5/*
6 * Test how array_diff() compares multidimensional arrays
7 */
8
9echo "*** Testing array_diff() : usage variations ***\n";
10
11$array1 = array('sub_array1' => array (1, 2, 3),
12                'sub_array2' => array ('a', 'b', 'c'));
13$array2 = array('sub_arraya' => array (1, 3, 5),
14                'sub_arrayb' => array ('a', 'z', 'y'));
15
16echo "-- Compare two 2-D arrays --\n";
17var_dump(array_diff($array1, $array2));
18var_dump(array_diff($array2, $array1));
19
20echo "\n-- Compare subarrays from two 2-D arrays --\n";
21var_dump(array_diff($array1['sub_array1'], $array2['sub_arraya']));
22var_dump(array_diff($array2['sub_arraya'], $array1['sub_array1']));
23
24var_dump(array_diff($array1['sub_array2'], $array2['sub_arrayb']));
25var_dump(array_diff($array2['sub_arrayb'], $array1['sub_array1']));
26
27echo "\n-- Compare a subarray from one 2-D array and one 2-D array --\n";
28var_dump(array_diff($array1['sub_array1'], $array2));
29var_dump(array_diff($array1, $array2['sub_arraya']));
30
31echo "Done";
32?>
33--EXPECTF--
34*** Testing array_diff() : usage variations ***
35-- Compare two 2-D arrays --
36
37Warning: Array to string conversion in %s on line %d
38
39Warning: Array to string conversion in %s on line %d
40
41Warning: Array to string conversion in %s on line %d
42
43Warning: Array to string conversion in %s on line %d
44array(0) {
45}
46
47Warning: Array to string conversion in %s on line %d
48
49Warning: Array to string conversion in %s on line %d
50
51Warning: Array to string conversion in %s on line %d
52
53Warning: Array to string conversion in %s on line %d
54array(0) {
55}
56
57-- Compare subarrays from two 2-D arrays --
58array(1) {
59  [1]=>
60  int(2)
61}
62array(1) {
63  [2]=>
64  int(5)
65}
66array(2) {
67  [1]=>
68  string(1) "b"
69  [2]=>
70  string(1) "c"
71}
72array(3) {
73  [0]=>
74  string(1) "a"
75  [1]=>
76  string(1) "z"
77  [2]=>
78  string(1) "y"
79}
80
81-- Compare a subarray from one 2-D array and one 2-D array --
82
83Warning: Array to string conversion in %s on line %d
84
85Warning: Array to string conversion in %s on line %d
86array(3) {
87  [0]=>
88  int(1)
89  [1]=>
90  int(2)
91  [2]=>
92  int(3)
93}
94
95Warning: Array to string conversion in %s on line %d
96
97Warning: Array to string conversion in %s on line %d
98array(2) {
99  ["sub_array1"]=>
100  array(3) {
101    [0]=>
102    int(1)
103    [1]=>
104    int(2)
105    [2]=>
106    int(3)
107  }
108  ["sub_array2"]=>
109  array(3) {
110    [0]=>
111    string(1) "a"
112    [1]=>
113    string(1) "b"
114    [2]=>
115    string(1) "c"
116  }
117}
118Done
119