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