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