1--TEST--
2Test krsort() function : usage variations - sort integer/float values
3--FILE--
4<?php
5/*
6 * Testing krsort() by providing array of integer/float/mixed values 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*/
12
13echo "*** Testing krsort() : usage variations ***\n";
14
15// diff. associative arrays to sort
16$various_arrays = array(
17  // negative/positive integer key value array
18  array(1 => 11, -2 => -11, 3 => 21, -4 => -21, 5 => 31, -6 => -31, 7 => 0, 8 => 41, -10 =>-41),
19
20  // mixed value array with different types of keys
21  array(1 => .0001, 2 => .0021, -3 => -.01, 4 => -1, 5 => 0, 6 => .09, 7 => 2, -8 => -.9, 9 => 10.6E-2,
22        -10 => -10.6E-2, 11 => 33)
23);
24
25// set of possible flag values
26$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC);
27
28$count = 1;
29echo "\n-- Testing krsort() by supplying various integer/float arrays --\n";
30
31// loop through to test krsort() with different arrays
32foreach ($various_arrays as $array) {
33  echo "\n-- Iteration $count --\n";
34
35  echo "- With default sort flag -\n";
36  $temp_array = $array;
37  var_dump(krsort($temp_array) );
38  var_dump($temp_array);
39
40  // loop through $flags array and call krsort() with all possible sort flag values
41  foreach($flags as $key => $flag){
42    echo "- Sort flag = $key -\n";
43    $temp_array = $array;
44    var_dump(krsort($temp_array, $flag) );
45    var_dump($temp_array);
46  }
47  $count++;
48}
49
50echo "Done\n";
51?>
52--EXPECT--
53*** Testing krsort() : usage variations ***
54
55-- Testing krsort() by supplying various integer/float arrays --
56
57-- Iteration 1 --
58- With default sort flag -
59bool(true)
60array(9) {
61  [8]=>
62  int(41)
63  [7]=>
64  int(0)
65  [5]=>
66  int(31)
67  [3]=>
68  int(21)
69  [1]=>
70  int(11)
71  [-2]=>
72  int(-11)
73  [-4]=>
74  int(-21)
75  [-6]=>
76  int(-31)
77  [-10]=>
78  int(-41)
79}
80- Sort flag = SORT_REGULAR -
81bool(true)
82array(9) {
83  [8]=>
84  int(41)
85  [7]=>
86  int(0)
87  [5]=>
88  int(31)
89  [3]=>
90  int(21)
91  [1]=>
92  int(11)
93  [-2]=>
94  int(-11)
95  [-4]=>
96  int(-21)
97  [-6]=>
98  int(-31)
99  [-10]=>
100  int(-41)
101}
102- Sort flag = SORT_NUMERIC -
103bool(true)
104array(9) {
105  [8]=>
106  int(41)
107  [7]=>
108  int(0)
109  [5]=>
110  int(31)
111  [3]=>
112  int(21)
113  [1]=>
114  int(11)
115  [-2]=>
116  int(-11)
117  [-4]=>
118  int(-21)
119  [-6]=>
120  int(-31)
121  [-10]=>
122  int(-41)
123}
124
125-- Iteration 2 --
126- With default sort flag -
127bool(true)
128array(11) {
129  [11]=>
130  int(33)
131  [9]=>
132  float(0.106)
133  [7]=>
134  int(2)
135  [6]=>
136  float(0.09)
137  [5]=>
138  int(0)
139  [4]=>
140  int(-1)
141  [2]=>
142  float(0.0021)
143  [1]=>
144  float(0.0001)
145  [-3]=>
146  float(-0.01)
147  [-8]=>
148  float(-0.9)
149  [-10]=>
150  float(-0.106)
151}
152- Sort flag = SORT_REGULAR -
153bool(true)
154array(11) {
155  [11]=>
156  int(33)
157  [9]=>
158  float(0.106)
159  [7]=>
160  int(2)
161  [6]=>
162  float(0.09)
163  [5]=>
164  int(0)
165  [4]=>
166  int(-1)
167  [2]=>
168  float(0.0021)
169  [1]=>
170  float(0.0001)
171  [-3]=>
172  float(-0.01)
173  [-8]=>
174  float(-0.9)
175  [-10]=>
176  float(-0.106)
177}
178- Sort flag = SORT_NUMERIC -
179bool(true)
180array(11) {
181  [11]=>
182  int(33)
183  [9]=>
184  float(0.106)
185  [7]=>
186  int(2)
187  [6]=>
188  float(0.09)
189  [5]=>
190  int(0)
191  [4]=>
192  int(-1)
193  [2]=>
194  float(0.0021)
195  [1]=>
196  float(0.0001)
197  [-3]=>
198  float(-0.01)
199  [-8]=>
200  float(-0.9)
201  [-10]=>
202  float(-0.106)
203}
204Done
205