1--TEST--
2Test rsort() function : basic functionality
3--FILE--
4<?php
5/* Prototype  : bool rsort(array &$array_arg [, int $sort_flags])
6 * Description: Sort an array in reverse order
7 * Source code: ext/standard/array.c
8 */
9
10/*
11 * Test basic functionality of rsort()
12 */
13
14echo "*** Testing rsort() : basic functionality ***\n";
15
16// associative array containing unsorted string values
17$unsorted_strings = array(
18	"l" => "lemon", "o" => "orange",
19	"O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20",
20	"b" => "banana",
21);
22
23// array with default keys containing unsorted numeric values
24$unsorted_numerics =  array( 100, 33, 555, 22 );
25
26echo "\n-- Testing rsort() by supplying string array, 'flag' value is defualt --\n";
27$temp_array = $unsorted_strings;
28var_dump( rsort($temp_array) );
29var_dump( $temp_array);
30
31echo "\n-- Testing rsort() by supplying numeric array, 'flag' value is defualt --\n";
32$temp_array = $unsorted_numerics;
33var_dump( rsort($temp_array) );
34var_dump( $temp_array);
35
36echo "\n-- Testing rsort() by supplying string array, 'flag' = SORT_REGULAR --\n";
37$temp_array = $unsorted_strings;
38var_dump( rsort($temp_array, SORT_REGULAR) );
39var_dump( $temp_array);
40
41echo "\n-- Testing rsort() by supplying numeric array, 'flag' = SORT_REGULAR --\n";
42$temp_array = $unsorted_numerics;
43var_dump( rsort($temp_array, SORT_REGULAR) );
44var_dump( $temp_array);
45
46echo "\n-- Testing rsort() by supplying string array, 'flag' = SORT_STRING --\n";
47$temp_array = $unsorted_strings;
48var_dump( rsort($temp_array, SORT_STRING) );
49var_dump( $temp_array);
50
51echo "\n-- Testing rsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n";
52$temp_array = $unsorted_strings;
53var_dump( rsort($temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true)
54var_dump( $temp_array);
55
56echo "\n-- Testing rsort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n";
57$temp_array = $unsorted_strings;
58var_dump( rsort($temp_array, SORT_NATURAL) ); // expecting : bool(true)
59var_dump( $temp_array);
60
61echo "\n-- Testing rsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n";
62$temp_array = $unsorted_strings;
63var_dump( rsort($temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true)
64var_dump( $temp_array);
65
66echo "\n-- Testing rsort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n";
67$temp_array = $unsorted_numerics;
68var_dump( rsort($temp_array, SORT_NUMERIC) );
69var_dump( $temp_array);
70
71echo "Done";
72?>
73
74--EXPECTF--
75*** Testing rsort() : basic functionality ***
76
77-- Testing rsort() by supplying string array, 'flag' value is defualt --
78bool(true)
79array(8) {
80  [0]=>
81  string(8) "orange20"
82  [1]=>
83  string(7) "orange2"
84  [2]=>
85  string(6) "orange"
86  [3]=>
87  string(5) "lemon"
88  [4]=>
89  string(6) "banana"
90  [5]=>
91  string(7) "Orange3"
92  [6]=>
93  string(7) "Orange1"
94  [7]=>
95  string(6) "Orange"
96}
97
98-- Testing rsort() by supplying numeric array, 'flag' value is defualt --
99bool(true)
100array(4) {
101  [0]=>
102  int(555)
103  [1]=>
104  int(100)
105  [2]=>
106  int(33)
107  [3]=>
108  int(22)
109}
110
111-- Testing rsort() by supplying string array, 'flag' = SORT_REGULAR --
112bool(true)
113array(8) {
114  [0]=>
115  string(8) "orange20"
116  [1]=>
117  string(7) "orange2"
118  [2]=>
119  string(6) "orange"
120  [3]=>
121  string(5) "lemon"
122  [4]=>
123  string(6) "banana"
124  [5]=>
125  string(7) "Orange3"
126  [6]=>
127  string(7) "Orange1"
128  [7]=>
129  string(6) "Orange"
130}
131
132-- Testing rsort() by supplying numeric array, 'flag' = SORT_REGULAR --
133bool(true)
134array(4) {
135  [0]=>
136  int(555)
137  [1]=>
138  int(100)
139  [2]=>
140  int(33)
141  [3]=>
142  int(22)
143}
144
145-- Testing rsort() by supplying string array, 'flag' = SORT_STRING --
146bool(true)
147array(8) {
148  [0]=>
149  string(8) "orange20"
150  [1]=>
151  string(7) "orange2"
152  [2]=>
153  string(6) "orange"
154  [3]=>
155  string(5) "lemon"
156  [4]=>
157  string(6) "banana"
158  [5]=>
159  string(7) "Orange3"
160  [6]=>
161  string(7) "Orange1"
162  [7]=>
163  string(6) "Orange"
164}
165
166-- Testing rsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --
167bool(true)
168array(8) {
169  [0]=>
170  string(7) "Orange3"
171  [1]=>
172  string(8) "orange20"
173  [2]=>
174  string(7) "orange2"
175  [3]=>
176  string(7) "Orange1"
177  [4]=>
178  string(6) "orange"
179  [5]=>
180  string(6) "Orange"
181  [6]=>
182  string(5) "lemon"
183  [7]=>
184  string(6) "banana"
185}
186
187-- Testing rsort() by supplying string array (natural), 'flag' = SORT_NATURAL --
188bool(true)
189array(8) {
190  [0]=>
191  string(8) "orange20"
192  [1]=>
193  string(7) "orange2"
194  [2]=>
195  string(6) "orange"
196  [3]=>
197  string(5) "lemon"
198  [4]=>
199  string(6) "banana"
200  [5]=>
201  string(7) "Orange3"
202  [6]=>
203  string(7) "Orange1"
204  [7]=>
205  string(6) "Orange"
206}
207
208-- Testing rsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --
209bool(true)
210array(8) {
211  [0]=>
212  string(8) "orange20"
213  [1]=>
214  string(7) "Orange3"
215  [2]=>
216  string(7) "orange2"
217  [3]=>
218  string(7) "Orange1"
219  [4]=>
220  string(6) "orange"
221  [5]=>
222  string(6) "Orange"
223  [6]=>
224  string(5) "lemon"
225  [7]=>
226  string(6) "banana"
227}
228
229-- Testing rsort() by supplying numeric array, 'flag' = SORT_NUMERIC --
230bool(true)
231array(4) {
232  [0]=>
233  int(555)
234  [1]=>
235  int(100)
236  [2]=>
237  int(33)
238  [3]=>
239  int(22)
240}
241Done