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