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