1--TEST--
2Test array_diff_assoc() function : variation - array containing different data types
3--FILE--
4<?php
5/*
6 * Test how array_diff_assoc() compares indexed arrays containing different data types
7 */
8
9echo "\n*** Testing array_diff_assoc() : usage variations ***\n";
10
11$array = array(1, 2, 3);
12
13//get an unset variable
14$unset_var = 10;
15unset ($unset_var);
16
17// get a class
18class classA
19{
20  public function __toString() {
21    return "Class A object";
22  }
23}
24
25// heredoc string
26$heredoc = <<<EOT
27hello world
28EOT;
29
30//array of different data types to be passed to $arr1 argument
31$inputs = array(
32
33       // int data
34/*1*/
35'int' => array(
36       0,
37       1,
38       12345,
39       -2345),
40
41       // float data
42/*2*/
43'float' => array(
44       10.5,
45       -10.5,
46       12.3456789000e10,
47       12.3456789000E-10,
48       .5),
49
50       // null data
51/*3*/
52'null' => array(
53       NULL,
54       null),
55
56       // boolean data
57/*4*/
58'bool' => array(
59       true,
60       false,
61       TRUE,
62       FALSE),
63
64       // empty data
65/*5*/
66'empty' => array(
67       "",
68       ''),
69
70       // string data
71/*6*/
72'string' => array(
73       "string",
74       'string',
75       $heredoc),
76
77       // binary data
78/*7*/
79'binary' => array(
80       b"binary",
81       (binary)"binary"),
82
83       // object data
84/*8*/
85'object' => array(
86      new classA()),
87
88       // undefined data
89/*9*/
90'undefined' => array(
91       @$undefined_var),
92
93       // unset data
94/*10*/
95'unset' => array(
96      @$unset_var),
97);
98
99// loop through each element of $inputs to check the behavior of array_diff_assoc
100$iterator = 1;
101foreach($inputs as $key => $input) {
102  echo "\n-- Iteration $iterator --\n";
103  var_dump( array_diff_assoc($input, $array));
104  $iterator++;
105};
106echo "Done";
107?>
108--EXPECTF--
109*** Testing array_diff_assoc() : usage variations ***
110
111-- Iteration 1 --
112array(4) {
113  [0]=>
114  int(0)
115  [1]=>
116  int(1)
117  [2]=>
118  int(12345)
119  [3]=>
120  int(-2345)
121}
122
123-- Iteration 2 --
124array(5) {
125  [0]=>
126  float(10.5)
127  [1]=>
128  float(-10.5)
129  [2]=>
130  float(123456789000)
131  [3]=>
132  float(1.23456789E-9)
133  [4]=>
134  float(0.5)
135}
136
137-- Iteration 3 --
138array(2) {
139  [0]=>
140  NULL
141  [1]=>
142  NULL
143}
144
145-- Iteration 4 --
146array(3) {
147  [1]=>
148  bool(false)
149  [2]=>
150  bool(true)
151  [3]=>
152  bool(false)
153}
154
155-- Iteration 5 --
156array(2) {
157  [0]=>
158  string(0) ""
159  [1]=>
160  string(0) ""
161}
162
163-- Iteration 6 --
164array(3) {
165  [0]=>
166  string(6) "string"
167  [1]=>
168  string(6) "string"
169  [2]=>
170  string(11) "hello world"
171}
172
173-- Iteration 7 --
174array(2) {
175  [0]=>
176  string(6) "binary"
177  [1]=>
178  string(6) "binary"
179}
180
181-- Iteration 8 --
182array(1) {
183  [0]=>
184  object(classA)#%d (0) {
185  }
186}
187
188-- Iteration 9 --
189array(1) {
190  [0]=>
191  NULL
192}
193
194-- Iteration 10 --
195array(1) {
196  [0]=>
197  NULL
198}
199Done
200