1--TEST--
2Test rsort() function : usage variations - String values
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6  die("skip Output tested contains chars that are not shown the same on windows concole (ESC and co)");
7}
8--FILE--
9<?php
10/* Prototype  : bool rsort(array &$array_arg [, int $sort_flags])
11 * Description: Sort an array in reverse order
12 * Source code: ext/standard/array.c
13 */
14
15/*
16 * Pass arrays containing different string data to rsort() to test behaviour
17 */
18
19echo "*** Testing rsort() : variation ***\n";
20
21$various_arrays = array (
22// group of escape sequences
23array(null, NULL, "\a", "\cx", "\e", "\f", "\n", "\t", "\xhh", "\ddd", "\v"),
24
25// array contains combination of capital/small letters
26array("lemoN", "Orange", "banana", "apple", "Test", "TTTT", "ttt", "ww", "x", "X", "oraNGe", "BANANA")
27);
28
29$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING);
30
31$count = 1;
32// loop through to test rsort() with different arrays
33foreach ($various_arrays as $array) {
34	echo "\n-- Iteration $count --\n";
35
36	echo "- With Default sort flag -\n";
37	$temp_array = $array;
38	var_dump(rsort($temp_array) );
39	var_dump($temp_array);
40
41	// loop through $flags array and setting all possible flag values
42	foreach($flags as $key => $flag){
43		echo "- Sort flag = $key -\n";
44
45		$temp_array = $array;
46		var_dump(rsort($temp_array, $flag) );
47		var_dump($temp_array);
48	}
49	$count++;
50}
51
52echo "Done";
53?>
54
55--EXPECTF--
56*** Testing rsort() : variation ***
57
58-- Iteration 1 --
59- With Default sort flag -
60bool(true)
61array(11) {
62  [0]=>
63  string(4) "\xhh"
64  [1]=>
65  string(4) "\ddd"
66  [2]=>
67  string(3) "\cx"
68  [3]=>
69  string(2) "\a"
70  [4]=>
71  string(1) ""
72  [5]=>
73  string(1) ""
74  [6]=>
75  string(1) ""
76  [7]=>
77  string(1) "
78"
79  [8]=>
80  string(1) "	"
81  [9]=>
82  NULL
83  [10]=>
84  NULL
85}
86- Sort flag = SORT_REGULAR -
87bool(true)
88array(11) {
89  [0]=>
90  string(4) "\xhh"
91  [1]=>
92  string(4) "\ddd"
93  [2]=>
94  string(3) "\cx"
95  [3]=>
96  string(2) "\a"
97  [4]=>
98  string(1) ""
99  [5]=>
100  string(1) ""
101  [6]=>
102  string(1) ""
103  [7]=>
104  string(1) "
105"
106  [8]=>
107  string(1) "	"
108  [9]=>
109  NULL
110  [10]=>
111  NULL
112}
113- Sort flag = SORT_STRING -
114bool(true)
115array(11) {
116  [0]=>
117  string(4) "\xhh"
118  [1]=>
119  string(4) "\ddd"
120  [2]=>
121  string(3) "\cx"
122  [3]=>
123  string(2) "\a"
124  [4]=>
125  string(1) ""
126  [5]=>
127  string(1) ""
128  [6]=>
129  string(1) ""
130  [7]=>
131  string(1) "
132"
133  [8]=>
134  string(1) "	"
135  [9]=>
136  NULL
137  [10]=>
138  NULL
139}
140
141-- Iteration 2 --
142- With Default sort flag -
143bool(true)
144array(12) {
145  [0]=>
146  string(1) "x"
147  [1]=>
148  string(2) "ww"
149  [2]=>
150  string(3) "ttt"
151  [3]=>
152  string(6) "oraNGe"
153  [4]=>
154  string(5) "lemoN"
155  [5]=>
156  string(6) "banana"
157  [6]=>
158  string(5) "apple"
159  [7]=>
160  string(1) "X"
161  [8]=>
162  string(4) "Test"
163  [9]=>
164  string(4) "TTTT"
165  [10]=>
166  string(6) "Orange"
167  [11]=>
168  string(6) "BANANA"
169}
170- Sort flag = SORT_REGULAR -
171bool(true)
172array(12) {
173  [0]=>
174  string(1) "x"
175  [1]=>
176  string(2) "ww"
177  [2]=>
178  string(3) "ttt"
179  [3]=>
180  string(6) "oraNGe"
181  [4]=>
182  string(5) "lemoN"
183  [5]=>
184  string(6) "banana"
185  [6]=>
186  string(5) "apple"
187  [7]=>
188  string(1) "X"
189  [8]=>
190  string(4) "Test"
191  [9]=>
192  string(4) "TTTT"
193  [10]=>
194  string(6) "Orange"
195  [11]=>
196  string(6) "BANANA"
197}
198- Sort flag = SORT_STRING -
199bool(true)
200array(12) {
201  [0]=>
202  string(1) "x"
203  [1]=>
204  string(2) "ww"
205  [2]=>
206  string(3) "ttt"
207  [3]=>
208  string(6) "oraNGe"
209  [4]=>
210  string(5) "lemoN"
211  [5]=>
212  string(6) "banana"
213  [6]=>
214  string(5) "apple"
215  [7]=>
216  string(1) "X"
217  [8]=>
218  string(4) "Test"
219  [9]=>
220  string(4) "TTTT"
221  [10]=>
222  string(6) "Orange"
223  [11]=>
224  string(6) "BANANA"
225}
226Done
227