1--TEST-- 2Test arsort() function : usage variations - unexpected values for 'sort_flags' argument 3--FILE-- 4<?php 5/* Prototype : proto bool arsort(array &array_arg [, int sort_flags]) 6 * Description: Sort an array and maintain index association 7 Elements will be arranged from highest to lowest when this function has completed. 8 * Source code: ext/standard/array.c 9*/ 10 11/* 12 * Testing arsort() by providing different unexpected values for flag argument 13*/ 14 15echo "*** Testing arsort() : usage variations ***\n"; 16 17//get an unset variable 18$unset_var = 10; 19unset ($unset_var); 20 21// resource variable 22$fp = fopen(__FILE__, "r"); 23 24// temperory array for checking unexpected behavior 25$unsorted_values = array(1 => 10, 2 => 2, 3 => 45); 26 27//array of values to iterate over 28$unexpected_values = array( 29 30 // int data 31/*1*/ -2345, 32 33 // float data 34/*2*/ 10.5, 35 -10.5, 36 10.5e2, 37 10.6E-2, 38 .5, 39 40 // null data 41/*7*/ NULL, 42 null, 43 44 // boolean data 45/*9*/ true, 46 false, 47 TRUE, 48 FALSE, 49 50 // empty data 51/*13*/ "", 52 '', 53 54 // string data 55/*15*/ "string", 56 'string', 57 58 // object data 59/*16*/ new stdclass(), 60 61 // undefined data 62/*17*/ @undefined_var, 63 64 // unset data 65/*18*/ @unset_var, 66 67 // resource variable 68/*19*/ $fp 69 70); 71 72// loop though each element of the array and check the working of arsort() 73// when $flag argument is supplied with different values from $unexpected_values 74echo "\n-- Testing arsort() by supplying different unexpected values for 'sort_flags' argument --\n"; 75 76$counter = 1; 77for($index = 0; $index < count($unexpected_values); $index ++) { 78 echo "-- Iteration $counter --\n"; 79 $value = $unexpected_values [$index]; 80 $temp_array = $unsorted_values; 81 var_dump( arsort($temp_array, $value) ); 82 var_dump($temp_array); 83 $counter++; 84} 85 86echo "Done"; 87?> 88--EXPECTF-- 89*** Testing arsort() : usage variations *** 90 91-- Testing arsort() by supplying different unexpected values for 'sort_flags' argument -- 92-- Iteration 1 -- 93bool(true) 94array(3) { 95 [3]=> 96 int(45) 97 [1]=> 98 int(10) 99 [2]=> 100 int(2) 101} 102-- Iteration 2 -- 103bool(true) 104array(3) { 105 [3]=> 106 int(45) 107 [2]=> 108 int(2) 109 [1]=> 110 int(10) 111} 112-- Iteration 3 -- 113bool(true) 114array(3) { 115 [3]=> 116 int(45) 117 [1]=> 118 int(10) 119 [2]=> 120 int(2) 121} 122-- Iteration 4 -- 123bool(true) 124array(3) { 125 [3]=> 126 int(45) 127 [1]=> 128 int(10) 129 [2]=> 130 int(2) 131} 132-- Iteration 5 -- 133bool(true) 134array(3) { 135 [3]=> 136 int(45) 137 [1]=> 138 int(10) 139 [2]=> 140 int(2) 141} 142-- Iteration 6 -- 143bool(true) 144array(3) { 145 [3]=> 146 int(45) 147 [1]=> 148 int(10) 149 [2]=> 150 int(2) 151} 152-- Iteration 7 -- 153bool(true) 154array(3) { 155 [3]=> 156 int(45) 157 [1]=> 158 int(10) 159 [2]=> 160 int(2) 161} 162-- Iteration 8 -- 163bool(true) 164array(3) { 165 [3]=> 166 int(45) 167 [1]=> 168 int(10) 169 [2]=> 170 int(2) 171} 172-- Iteration 9 -- 173bool(true) 174array(3) { 175 [3]=> 176 int(45) 177 [1]=> 178 int(10) 179 [2]=> 180 int(2) 181} 182-- Iteration 10 -- 183bool(true) 184array(3) { 185 [3]=> 186 int(45) 187 [1]=> 188 int(10) 189 [2]=> 190 int(2) 191} 192-- Iteration 11 -- 193bool(true) 194array(3) { 195 [3]=> 196 int(45) 197 [1]=> 198 int(10) 199 [2]=> 200 int(2) 201} 202-- Iteration 12 -- 203bool(true) 204array(3) { 205 [3]=> 206 int(45) 207 [1]=> 208 int(10) 209 [2]=> 210 int(2) 211} 212-- Iteration 13 -- 213 214Warning: arsort() expects parameter 2 to be integer, string given in %sarsort_variation2.php on line %d 215bool(false) 216array(3) { 217 [1]=> 218 int(10) 219 [2]=> 220 int(2) 221 [3]=> 222 int(45) 223} 224-- Iteration 14 -- 225 226Warning: arsort() expects parameter 2 to be integer, string given in %sarsort_variation2.php on line %d 227bool(false) 228array(3) { 229 [1]=> 230 int(10) 231 [2]=> 232 int(2) 233 [3]=> 234 int(45) 235} 236-- Iteration 15 -- 237 238Warning: arsort() expects parameter 2 to be integer, string given in %sarsort_variation2.php on line %d 239bool(false) 240array(3) { 241 [1]=> 242 int(10) 243 [2]=> 244 int(2) 245 [3]=> 246 int(45) 247} 248-- Iteration 16 -- 249 250Warning: arsort() expects parameter 2 to be integer, string given in %sarsort_variation2.php on line %d 251bool(false) 252array(3) { 253 [1]=> 254 int(10) 255 [2]=> 256 int(2) 257 [3]=> 258 int(45) 259} 260-- Iteration 17 -- 261 262Warning: arsort() expects parameter 2 to be integer, object given in %sarsort_variation2.php on line %d 263bool(false) 264array(3) { 265 [1]=> 266 int(10) 267 [2]=> 268 int(2) 269 [3]=> 270 int(45) 271} 272-- Iteration 18 -- 273 274Warning: arsort() expects parameter 2 to be integer, string given in %sarsort_variation2.php on line %d 275bool(false) 276array(3) { 277 [1]=> 278 int(10) 279 [2]=> 280 int(2) 281 [3]=> 282 int(45) 283} 284-- Iteration 19 -- 285 286Warning: arsort() expects parameter 2 to be integer, string given in %sarsort_variation2.php on line %d 287bool(false) 288array(3) { 289 [1]=> 290 int(10) 291 [2]=> 292 int(2) 293 [3]=> 294 int(45) 295} 296-- Iteration 20 -- 297 298Warning: arsort() expects parameter 2 to be integer, resource given in %sarsort_variation2.php on line %d 299bool(false) 300array(3) { 301 [1]=> 302 int(10) 303 [2]=> 304 int(2) 305 [3]=> 306 int(45) 307} 308Done 309