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