Annotation of embedaddon/php/ext/standard/tests/array/array_unique_variation2.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test 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:
15: echo "*** 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:
22: EOT;
23:
24: // heredoc with multiline string
25: $multiline_string = <<<EOT
26: hello world
27: The quick brown fox jumped over;
28: the lazy dog
29: This is a double quoted string
30: EOT;
31:
1.1.1.2 ! misho 32: // heredoc with different whitespaces
1.1 misho 33: $diff_whitespaces = <<<EOT
34: hello\r world\t
35: 1111\t\t != 2222\v\v
36: heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces
37: EOT;
38:
39: // heredoc with quoted strings and numeric values
40: $numeric_string = <<<EOT
41: 11 < 12. 123 >22
42: 'single quoted string'
43: "double quoted string"
44: 2222 != 1111.\t 0000 = 0000\n
45: EOT;
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;
75: foreach($inputs as $input) {
76: echo "-- Iteration $iterator --\n";
77: var_dump( array_unique($input, SORT_STRING) );
78: $iterator++;
79: }
80:
81: echo "Done";
82: ?>
83: --EXPECTF--
84: *** Testing array_unique() : Passing different arrays to $input argument ***
85: -- Iteration 1 --
86: array(2) {
87: [0]=>
88: int(1)
89: [1]=>
90: int(2)
91: }
92: -- Iteration 2 --
93: array(2) {
94: [0]=>
95: float(1.1)
96: [1]=>
97: float(2.2)
98: }
99: -- Iteration 3 --
100: array(2) {
101: [0]=>
102: bool(false)
103: [1]=>
104: bool(true)
105: }
106: -- Iteration 4 --
107: array(0) {
108: }
109: -- Iteration 5 --
110: array(1) {
111: [0]=>
112: NULL
113: }
114: -- Iteration 6 --
115: array(4) {
116: [0]=>
117: %unicode|string%(3) "a"
118: [1]=>
119: %unicode|string%(5) "aaaa
"
120: [2]=>
121: %unicode|string%(1) "b"
122: [4]=>
123: %unicode|string%(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}"
124: }
125: -- Iteration 7 --
126: array(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 --
137: array(3) {
138: [%b|u%"h1"]=>
139: %unicode|string%(1) "
140: "
141: [%b|u%"h2"]=>
142: %unicode|string%(88) "hello world
143: The quick brown fox jumped over;
144: the lazy dog
145: This is a double quoted string"
146: [%b|u%"h3"]=>
147: %unicode|string%(88) "hello
world
148: 1111 != 2222
149: heredoc
150: double quoted string. withdifferentwhitespaces"
151: }
152: -- Iteration 9 --
153: array(2) {
154: [1]=>
155: %unicode|string%(3) "one"
156: [2]=>
157: %unicode|string%(3) "two"
158: }
159: -- Iteration 10 --
160: array(2) {
161: [%b|u%"one"]=>
162: int(1)
163: [%b|u%"two"]=>
164: int(2)
165: }
166: -- Iteration 11 --
167: array(3) {
168: [1]=>
169: int(10)
170: [2]=>
171: int(20)
172: [4]=>
173: int(40)
174: }
175: -- Iteration 12 --
176: array(2) {
177: [%b|u%"one"]=>
178: %unicode|string%(3) "ten"
179: [%b|u%"two"]=>
180: %unicode|string%(6) "twenty"
181: }
182: -- Iteration 13 --
183: array(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 --
192: array(2) {
193: [%b|u%""]=>
194: %unicode|string%(4) "null"
195: [%b|u%"NULL"]=>
196: NULL
197: }
198: -- Iteration 15 --
199: array(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 --
210: array(2) {
211: [%b|u%""]=>
212: %unicode|string%(6) "emptys"
213: [%b|u%"emptyd"]=>
214: %unicode|string%(0) ""
215: }
216: -- Iteration 17 --
217: array(2) {
218: [1]=>
219: %unicode|string%(0) ""
220: [6]=>
221: bool(true)
222: }
223: -- Iteration 18 --
224: array(3) {
225: [%b|u%""]=>
226: int(4)
227: [0]=>
228: int(5)
229: [1]=>
230: int(6)
231: }
232: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>