1--TEST--
2Test array_unique() function : usage variations - different arrays for 'input' argument
3--FILE--
4<?php
5/*
6* Passing different arrays to $input argument and testing whether
7* array_unique() behaves in an expected way.
8*/
9
10echo "*** Testing array_unique() : Passing different arrays to \$input argument ***\n";
11
12/* Different heredoc strings passed as argument to arrays */
13// heredoc with blank line
14$blank_line = <<<EOT
15
16
17EOT;
18
19// heredoc with multiline string
20$multiline_string = <<<EOT
21hello world
22The quick brown fox jumped over;
23the lazy dog
24This is a double quoted string
25EOT;
26
27// heredoc with different whitespaces
28$diff_whitespaces = <<<EOT
29hello\r world\t
301111\t\t != 2222\v\v
31heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces
32EOT;
33
34// heredoc with quoted strings and numeric values
35$numeric_string = <<<EOT
3611 < 12. 123 >22
37'single quoted string'
38"double quoted string"
392222 != 1111.\t 0000 = 0000\n
40EOT;
41
42// arrays passed to $input argument
43$inputs = array (
44/*1*/  array(1, 2, 2, 1), // with default keys and numeric values
45       array(1.1, 2.2, 1.1), // with default keys & float values
46       array(false, true, false), // with default keys and boolean values
47       array(), // empty array
48/*5*/  array(NULL, null), // with NULL
49       array("a\v\f", "aaaa\r", "b", "aaaa\r", "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"),  // with double quoted strings
50       array('a\v\f', 'aaaa\r', 'b', 'aaaa\r', '\[\]\!\@\#\$\%\^\&\*\(\)\{\}'),  // with single quoted strings
51       array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $blank_line),  // with heredocs
52
53       // associative arrays
54/*9*/  array(1 => "one", 2 => "two", 2 => "two"),  // explicit numeric keys, string values
55       array("one" => 1, "two" => 2, "1" => 1 ),  // string keys & numeric values
56       array( 1 => 10, 2 => 20, 4 => 40, 5 => 10),  // explicit numeric keys and numeric values
57       array( "one" => "ten", "two" => "twenty", "10" => "ten"),  // string key/value
58       array("one" => 1, 2 => "two", 4 => "four"),  //mixed
59
60       // associative array, containing null/empty/boolean values as key/value
61/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null),
62       array(true => "true", false => "false", "false" => false, "true" => true),
63       array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''),
64       array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true),
65/*18*/ array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6),
66);
67
68// loop through each sub-array of $inputs to check the behavior of array_unique()
69$iterator = 1;
70foreach($inputs as $input) {
71  echo "-- Iteration $iterator --\n";
72  var_dump( array_unique($input, SORT_STRING) );
73  $iterator++;
74}
75
76echo "Done";
77?>
78--EXPECT--
79*** Testing array_unique() : Passing different arrays to $input argument ***
80-- Iteration 1 --
81array(2) {
82  [0]=>
83  int(1)
84  [1]=>
85  int(2)
86}
87-- Iteration 2 --
88array(2) {
89  [0]=>
90  float(1.1)
91  [1]=>
92  float(2.2)
93}
94-- Iteration 3 --
95array(2) {
96  [0]=>
97  bool(false)
98  [1]=>
99  bool(true)
100}
101-- Iteration 4 --
102array(0) {
103}
104-- Iteration 5 --
105array(1) {
106  [0]=>
107  NULL
108}
109-- Iteration 6 --
110array(4) {
111  [0]=>
112  string(3) "a"
113  [1]=>
114  string(5) "aaaa
114"
115  [2]=>
116  string(1) "b"
117  [4]=>
118  string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}"
119}
120-- Iteration 7 --
121array(4) {
122  [0]=>
123  string(5) "a\v\f"
124  [1]=>
125  string(6) "aaaa\r"
126  [2]=>
127  string(1) "b"
128  [4]=>
129  string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"
130}
131-- Iteration 8 --
132array(3) {
133  ["h1"]=>
134  string(1) "
135"
136  ["h2"]=>
137  string(88) "hello world
138The quick brown fox jumped over;
139the lazy dog
140This is a double quoted string"
141  ["h3"]=>
142  string(88) "hello
142 world
1431111		 != 2222
144heredoc
145double quoted string. withdifferentwhitespaces"
146}
147-- Iteration 9 --
148array(2) {
149  [1]=>
150  string(3) "one"
151  [2]=>
152  string(3) "two"
153}
154-- Iteration 10 --
155array(2) {
156  ["one"]=>
157  int(1)
158  ["two"]=>
159  int(2)
160}
161-- Iteration 11 --
162array(3) {
163  [1]=>
164  int(10)
165  [2]=>
166  int(20)
167  [4]=>
168  int(40)
169}
170-- Iteration 12 --
171array(2) {
172  ["one"]=>
173  string(3) "ten"
174  ["two"]=>
175  string(6) "twenty"
176}
177-- Iteration 13 --
178array(3) {
179  ["one"]=>
180  int(1)
181  [2]=>
182  string(3) "two"
183  [4]=>
184  string(4) "four"
185}
186-- Iteration 14 --
187array(2) {
188  [""]=>
189  string(4) "null"
190  ["NULL"]=>
191  NULL
192}
193-- Iteration 15 --
194array(4) {
195  [1]=>
196  string(4) "true"
197  [0]=>
198  string(5) "false"
199  ["false"]=>
200  bool(false)
201  ["true"]=>
202  bool(true)
203}
204-- Iteration 16 --
205array(2) {
206  [""]=>
207  string(6) "emptys"
208  ["emptyd"]=>
209  string(0) ""
210}
211-- Iteration 17 --
212array(2) {
213  [1]=>
214  string(0) ""
215  [6]=>
216  bool(true)
217}
218-- Iteration 18 --
219array(3) {
220  [""]=>
221  int(4)
222  [0]=>
223  int(5)
224  [1]=>
225  int(6)
226}
227Done
228