1--TEST--
2Test array_diff_assoc() function : usage variations - arrays with different data types as keys
3--FILE--
4<?php
5/*
6 * Test how array_diff_assoc() compares arrays containing different data types
7 * as keys
8 */
9
10echo "\n*** Testing array_diff_assoc() : usage variations ***\n";
11
12$array = array(1, 2, 3);
13
14//get an unset variable
15$unset_var = 10;
16unset ($unset_var);
17
18// heredoc string
19$heredoc = <<<EOT
20hello world
21EOT;
22
23//Different data types as keys to be passed to $arr1 argument
24$inputs = array(
25
26       // int data
27/*1*/
28'int' => array(
29       0 => 'zero',
30       1 => 'one',
31       12345 => 'positive',
32       -2345 => 'negative'),
33
34       // null data
35/*3*/
36'null' => array(
37       NULL => 'null 1',
38       null => 'null 2'),
39
40       // boolean data
41/*4*/
42'bool' => array(
43       true => 'boolt',
44       false => 'boolf',
45       TRUE => 'boolT',
46       FALSE => 'boolF'),
47
48       // empty data
49/*5*/
50'empty' => array(
51      "" => 'emptyd',
52      '' => 'emptys'),
53
54       // string data
55/*6*/
56'string' => array(
57      "string" => 'stringd',
58      'string' => 'strings',
59      $heredoc => 'stringh'),
60
61       // binary data
62/*7*/
63'binary' => array(
64      b"binary1" => 'binary 1',
65      (binary)"binary2" => 'binary 2'),
66
67       // undefined data
68/*8*/
69'undefined' => array(
70      @$undefined_var => 'undefined'),
71
72       // unset data
73/*9*/
74'unset' => array(
75      @$unset_var => 'unset'),
76
77);
78
79// loop through each element of $inputs to check the behavior of array_diff_assoc
80$iterator = 1;
81foreach($inputs as $key => $input) {
82  echo "\n-- Iteration $iterator --\n";
83  var_dump( array_diff_assoc($input, $array));
84  $iterator++;
85};
86
87echo "Done";
88?>
89--EXPECT--
90*** Testing array_diff_assoc() : usage variations ***
91
92-- Iteration 1 --
93array(4) {
94  [0]=>
95  string(4) "zero"
96  [1]=>
97  string(3) "one"
98  [12345]=>
99  string(8) "positive"
100  [-2345]=>
101  string(8) "negative"
102}
103
104-- Iteration 2 --
105array(1) {
106  [""]=>
107  string(6) "null 2"
108}
109
110-- Iteration 3 --
111array(2) {
112  [1]=>
113  string(5) "boolT"
114  [0]=>
115  string(5) "boolF"
116}
117
118-- Iteration 4 --
119array(1) {
120  [""]=>
121  string(6) "emptys"
122}
123
124-- Iteration 5 --
125array(2) {
126  ["string"]=>
127  string(7) "strings"
128  ["hello world"]=>
129  string(7) "stringh"
130}
131
132-- Iteration 6 --
133array(2) {
134  ["binary1"]=>
135  string(8) "binary 1"
136  ["binary2"]=>
137  string(8) "binary 2"
138}
139
140-- Iteration 7 --
141array(1) {
142  [""]=>
143  string(9) "undefined"
144}
145
146-- Iteration 8 --
147array(1) {
148  [""]=>
149  string(5) "unset"
150}
151Done
152