1--TEST-- 2Test arsort() function : usage variations - sort hexadecimal values 3--FILE-- 4<?php 5/* 6 * testing arsort() 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 arsort() : 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 arsort() by supplying hexadecimal value array, 'flag' value is default --\n"; 21$temp_array = $unsorted_hex_array; 22var_dump(arsort($temp_array) ); // expecting : bool(true) 23var_dump($temp_array); 24 25echo "\n-- Testing arsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --\n"; 26$temp_array = $unsorted_hex_array; 27var_dump(arsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) 28var_dump($temp_array); 29 30echo "\n-- Testing arsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --\n"; 31$temp_array = $unsorted_hex_array; 32var_dump(arsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) 33var_dump($temp_array); 34 35echo "Done\n"; 36?> 37--EXPECT-- 38*** Testing arsort() : usage variations *** 39 40-- Testing arsort() by supplying hexadecimal value array, 'flag' value is default -- 41bool(true) 42array(9) { 43 [4095]=> 44 int(4095) 45 [682]=> 46 int(682) 47 [427]=> 48 int(427) 49 [255]=> 50 int(255) 51 [187]=> 52 int(187) 53 [15]=> 54 int(15) 55 [0]=> 56 int(0) 57 [-255]=> 58 int(-255) 59 [-682]=> 60 int(-682) 61} 62 63-- Testing arsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR -- 64bool(true) 65array(9) { 66 [4095]=> 67 int(4095) 68 [682]=> 69 int(682) 70 [427]=> 71 int(427) 72 [255]=> 73 int(255) 74 [187]=> 75 int(187) 76 [15]=> 77 int(15) 78 [0]=> 79 int(0) 80 [-255]=> 81 int(-255) 82 [-682]=> 83 int(-682) 84} 85 86-- Testing arsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC -- 87bool(true) 88array(9) { 89 [4095]=> 90 int(4095) 91 [682]=> 92 int(682) 93 [427]=> 94 int(427) 95 [255]=> 96 int(255) 97 [187]=> 98 int(187) 99 [15]=> 100 int(15) 101 [0]=> 102 int(0) 103 [-255]=> 104 int(-255) 105 [-682]=> 106 int(-682) 107} 108Done 109