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