1--TEST--
2Test arsort() function : usage variations - sort integer/float values
3--FILE--
4<?php
5/*
6 * Testing arsort() by providing different integer/float value arrays for $array argument with following values
7 * 1. flag value as default
8 * 2. SORT_REGULAR - compare items normally
9 * 3. SORT_NUMERIC - compare items numerically
10*/
11
12echo "*** Testing arsort() : usage variations ***\n";
13
14// group of various arrays with indices
15$various_arrays = array(
16  // negative/posative integer array
17  array(1 => 11, 2 => -11, 3 => 21, 4 => -21, 5 => 31, 6 => -31, 7 => 0, 8 => 41, 10 =>-41),
18
19  // float value array
20  array(1 => 10.5, 2 => -10.5, 3 => 10.5e2, 4 => 10.6E-2, 5 => .5, 6 => .0001, 7 => -.1),
21
22  // mixed value array
23  array(1 => .0001, 2 => .0021, 3 => -.01, 4 => -1, 5 => 0, 6 => .09, 7 => 2, 8 => -.9, 9 => 10.6E-2, 10 => -10.6E-2, 11 => 33),
24
25  // array values contains minimum and maximum ranges
26  array(1 => 2147483647, 2 => 2147483648, 3 => -2147483647, 4 => -2147483648, 5 => -0, 6 => 0, 7 => -2147483649)
27);
28
29// set of possible flag values
30$flag_value = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC);
31
32$count = 1;
33echo "\n-- Testing arsort() by supplying various integer/float arrays --\n";
34
35// loop through to test arsort() with different arrays
36foreach ($various_arrays as $array) {
37  echo "\n-- Iteration $count --\n";
38
39  echo "- With default sort_flag -\n";
40  $temp_array = $array;
41  var_dump(arsort($temp_array) );
42  var_dump($temp_array);
43
44  // loop through $flag_value array and setting all possible flag values
45  foreach($flag_value as $key => $flag){
46    echo "- Sort_flag = $key -\n";
47    $temp_array = $array;
48    var_dump(arsort($temp_array, $flag) );
49    var_dump($temp_array);
50  }
51  $count++;
52}
53
54echo "Done\n";
55?>
56--EXPECTF--
57*** Testing arsort() : usage variations ***
58
59-- Testing arsort() by supplying various integer/float arrays --
60
61-- Iteration 1 --
62- With default sort_flag -
63bool(true)
64array(9) {
65  [8]=>
66  int(41)
67  [5]=>
68  int(31)
69  [3]=>
70  int(21)
71  [1]=>
72  int(11)
73  [7]=>
74  int(0)
75  [2]=>
76  int(-11)
77  [4]=>
78  int(-21)
79  [6]=>
80  int(-31)
81  [10]=>
82  int(-41)
83}
84- Sort_flag = SORT_REGULAR -
85bool(true)
86array(9) {
87  [8]=>
88  int(41)
89  [5]=>
90  int(31)
91  [3]=>
92  int(21)
93  [1]=>
94  int(11)
95  [7]=>
96  int(0)
97  [2]=>
98  int(-11)
99  [4]=>
100  int(-21)
101  [6]=>
102  int(-31)
103  [10]=>
104  int(-41)
105}
106- Sort_flag = SORT_NUMERIC -
107bool(true)
108array(9) {
109  [8]=>
110  int(41)
111  [5]=>
112  int(31)
113  [3]=>
114  int(21)
115  [1]=>
116  int(11)
117  [7]=>
118  int(0)
119  [2]=>
120  int(-11)
121  [4]=>
122  int(-21)
123  [6]=>
124  int(-31)
125  [10]=>
126  int(-41)
127}
128
129-- Iteration 2 --
130- With default sort_flag -
131bool(true)
132array(7) {
133  [3]=>
134  float(1050)
135  [1]=>
136  float(10.5)
137  [5]=>
138  float(0.5)
139  [4]=>
140  float(0.106)
141  [6]=>
142  float(0.0001)
143  [7]=>
144  float(-0.1)
145  [2]=>
146  float(-10.5)
147}
148- Sort_flag = SORT_REGULAR -
149bool(true)
150array(7) {
151  [3]=>
152  float(1050)
153  [1]=>
154  float(10.5)
155  [5]=>
156  float(0.5)
157  [4]=>
158  float(0.106)
159  [6]=>
160  float(0.0001)
161  [7]=>
162  float(-0.1)
163  [2]=>
164  float(-10.5)
165}
166- Sort_flag = SORT_NUMERIC -
167bool(true)
168array(7) {
169  [3]=>
170  float(1050)
171  [1]=>
172  float(10.5)
173  [5]=>
174  float(0.5)
175  [4]=>
176  float(0.106)
177  [6]=>
178  float(0.0001)
179  [7]=>
180  float(-0.1)
181  [2]=>
182  float(-10.5)
183}
184
185-- Iteration 3 --
186- With default sort_flag -
187bool(true)
188array(11) {
189  [11]=>
190  int(33)
191  [7]=>
192  int(2)
193  [9]=>
194  float(0.106)
195  [6]=>
196  float(0.09)
197  [2]=>
198  float(0.0021)
199  [1]=>
200  float(0.0001)
201  [5]=>
202  int(0)
203  [3]=>
204  float(-0.01)
205  [10]=>
206  float(-0.106)
207  [8]=>
208  float(-0.9)
209  [4]=>
210  int(-1)
211}
212- Sort_flag = SORT_REGULAR -
213bool(true)
214array(11) {
215  [11]=>
216  int(33)
217  [7]=>
218  int(2)
219  [9]=>
220  float(0.106)
221  [6]=>
222  float(0.09)
223  [2]=>
224  float(0.0021)
225  [1]=>
226  float(0.0001)
227  [5]=>
228  int(0)
229  [3]=>
230  float(-0.01)
231  [10]=>
232  float(-0.106)
233  [8]=>
234  float(-0.9)
235  [4]=>
236  int(-1)
237}
238- Sort_flag = SORT_NUMERIC -
239bool(true)
240array(11) {
241  [11]=>
242  int(33)
243  [7]=>
244  int(2)
245  [9]=>
246  float(0.106)
247  [6]=>
248  float(0.09)
249  [2]=>
250  float(0.0021)
251  [1]=>
252  float(0.0001)
253  [5]=>
254  int(0)
255  [3]=>
256  float(-0.01)
257  [10]=>
258  float(-0.106)
259  [8]=>
260  float(-0.9)
261  [4]=>
262  int(-1)
263}
264
265-- Iteration 4 --
266- With default sort_flag -
267bool(true)
268array(7) {
269  [2]=>
270  %s(2147483648)
271  [1]=>
272  int(2147483647)
273  [5]=>
274  int(0)
275  [6]=>
276  int(0)
277  [3]=>
278  int(-2147483647)
279  [4]=>
280  %s(-2147483648)
281  [7]=>
282  %s(-2147483649)
283}
284- Sort_flag = SORT_REGULAR -
285bool(true)
286array(7) {
287  [2]=>
288  %s(2147483648)
289  [1]=>
290  int(2147483647)
291  [5]=>
292  int(0)
293  [6]=>
294  int(0)
295  [3]=>
296  int(-2147483647)
297  [4]=>
298  %s(-2147483648)
299  [7]=>
300  %s(-2147483649)
301}
302- Sort_flag = SORT_NUMERIC -
303bool(true)
304array(7) {
305  [2]=>
306  %s(2147483648)
307  [1]=>
308  int(2147483647)
309  [5]=>
310  int(0)
311  [6]=>
312  int(0)
313  [3]=>
314  int(-2147483647)
315  [4]=>
316  %s(-2147483648)
317  [7]=>
318  %s(-2147483649)
319}
320Done
321