1--TEST-- 2Test asort() function : usage variations - sort hexadecimal values 3--FILE-- 4<?php 5/* 6 * testing asort() by providing different hexa-decimal array for $array argument with following flag values 7 * flag value as default 8 * SORT_REGULAR - compare items normally 9 * SORT_NUMERIC - compare items numerically 10*/ 11 12echo "*** Testing asort() : usage variations ***\n"; 13 14// an array contains unsorted hexadecimal values 15// There are multiple keys which are duplicate and the later should be picked 16$unsorted_hex_array = array ( 0x1AB => 0x1AB, 0xFFF => 0xFFF, 0xF => 0xF, 0xFF => 0xFF, 0x2AA => 0x2AA, 0xBB => 0xBB, 17 0x1ab => 0x1ab, 0xff => 0xff, -0xff => -0xFF, 0 => 0, -0x2aa => -0x2aa 18 ); 19 20echo "\n-- Testing asort() by supplying hexadecimal value array, 'flag' value is default --\n"; 21$temp_array = $unsorted_hex_array; 22var_dump(asort($temp_array) ); // expecting : bool(true) 23var_dump($temp_array); 24 25echo "\n-- Testing asort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --\n"; 26$temp_array = $unsorted_hex_array; 27var_dump(asort($temp_array, SORT_REGULAR) ); // expecting : bool(true) 28var_dump($temp_array); 29 30echo "\n-- Testing asort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --\n"; 31$temp_array = $unsorted_hex_array; 32var_dump(asort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) 33var_dump($temp_array); 34 35echo "Done\n"; 36?> 37--EXPECT-- 38*** Testing asort() : usage variations *** 39 40-- Testing asort() by supplying hexadecimal value array, 'flag' value is default -- 41bool(true) 42array(9) { 43 [-682]=> 44 int(-682) 45 [-255]=> 46 int(-255) 47 [0]=> 48 int(0) 49 [15]=> 50 int(15) 51 [187]=> 52 int(187) 53 [255]=> 54 int(255) 55 [427]=> 56 int(427) 57 [682]=> 58 int(682) 59 [4095]=> 60 int(4095) 61} 62 63-- Testing asort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR -- 64bool(true) 65array(9) { 66 [-682]=> 67 int(-682) 68 [-255]=> 69 int(-255) 70 [0]=> 71 int(0) 72 [15]=> 73 int(15) 74 [187]=> 75 int(187) 76 [255]=> 77 int(255) 78 [427]=> 79 int(427) 80 [682]=> 81 int(682) 82 [4095]=> 83 int(4095) 84} 85 86-- Testing asort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC -- 87bool(true) 88array(9) { 89 [-682]=> 90 int(-682) 91 [-255]=> 92 int(-255) 93 [0]=> 94 int(0) 95 [15]=> 96 int(15) 97 [187]=> 98 int(187) 99 [255]=> 100 int(255) 101 [427]=> 102 int(427) 103 [682]=> 104 int(682) 105 [4095]=> 106 int(4095) 107} 108Done 109