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