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