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