1--TEST--
2Test array_diff() function : usage variations - comparing integers, float
3and string array values
4--FILE--
5<?php
6/* Prototype  : array array_diff(array $arr1, array $arr2 [, array ...])
7 * Description: Returns the entries of $arr1 that have values which are not
8 * present in any of the others arguments.
9 * Source code: ext/standard/array.c
10 */
11
12/*
13 * Test how array_diff compares integers, floats and strings
14 */
15
16echo "*** Testing array_diff() : usage variations ***\n";
17
18$arr_int = array(1, 2, 3);
19$arr_float = array(1.00, 2.00, 3.00);
20$arr_int_str = array('1', '2', '3');
21$arr_float_str = array('1.00', '2.00', '3.00');
22
23print "-- Compare integers and floats: --\n";
24var_dump(array_diff($arr_int, $arr_float));
25var_dump(array_diff($arr_float, $arr_int));
26
27
28print "-- Compare integers and strings containing an integers: --\n";
29var_dump(array_diff($arr_int, $arr_int_str));
30var_dump(array_diff($arr_int_str, $arr_int));
31
32print "-- Compare integers and strings containing floats: --\n";
33var_dump(array_diff($arr_int, $arr_float_str));
34var_dump(array_diff($arr_float_str, $arr_int));
35
36print "-- Compare floats and strings containing integers: --\n";
37
38var_dump(array_diff($arr_float, $arr_int_str));
39var_dump(array_diff($arr_int_str, $arr_float));
40
41print "-- Compare floats and strings containing floats: --\n";
42var_dump(array_diff($arr_float, $arr_float_str));
43var_dump(array_diff($arr_float_str, $arr_float));
44
45print "-- Compare strings containing integers and strings containing floats: --\n";
46var_dump(array_diff($arr_int_str, $arr_float_str));
47var_dump(array_diff($arr_float_str, $arr_int_str));
48
49echo "Done";
50?>
51--EXPECTF--
52*** Testing array_diff() : usage variations ***
53-- Compare integers and floats: --
54array(0) {
55}
56array(0) {
57}
58-- Compare integers and strings containing an integers: --
59array(0) {
60}
61array(0) {
62}
63-- Compare integers and strings containing floats: --
64array(3) {
65  [0]=>
66  int(1)
67  [1]=>
68  int(2)
69  [2]=>
70  int(3)
71}
72array(3) {
73  [0]=>
74  string(4) "1.00"
75  [1]=>
76  string(4) "2.00"
77  [2]=>
78  string(4) "3.00"
79}
80-- Compare floats and strings containing integers: --
81array(0) {
82}
83array(0) {
84}
85-- Compare floats and strings containing floats: --
86array(3) {
87  [0]=>
88  float(1)
89  [1]=>
90  float(2)
91  [2]=>
92  float(3)
93}
94array(3) {
95  [0]=>
96  string(4) "1.00"
97  [1]=>
98  string(4) "2.00"
99  [2]=>
100  string(4) "3.00"
101}
102-- Compare strings containing integers and strings containing floats: --
103array(3) {
104  [0]=>
105  string(1) "1"
106  [1]=>
107  string(1) "2"
108  [2]=>
109  string(1) "3"
110}
111array(3) {
112  [0]=>
113  string(4) "1.00"
114  [1]=>
115  string(4) "2.00"
116  [2]=>
117  string(4) "3.00"
118}
119Done