Annotation of embedaddon/php/ext/standard/tests/array/ksort_variation6.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test ksort() function : usage variations - sort hexadecimal values
! 3: --FILE--
! 4: <?php
! 5: /* Prototype : bool ksort ( array &$array [, int $sort_flags] )
! 6: * Description: Sort an array by key, maintaining key to data correlation.
! 7: * Source code: ext/standard/array.c
! 8: */
! 9:
! 10: /*
! 11: * testing ksort() by providing array of hexa-decimal values for $array argument with following flag values:
! 12: * 1.flag value as defualt
! 13: * 2.SORT_REGULAR - compare items normally
! 14: * 3.SORT_NUMERIC - compare items numerically
! 15: */
! 16:
! 17: echo "*** Testing ksort() : usage variations ***\n";
! 18:
! 19: // an array containng unsorted hexadecimal values with keys
! 20: // There are multiple keys which are duplicate and the later should be picked
! 21: $unsorted_hex_array = array (
! 22: 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:
! 26: echo "\n-- Testing ksort() by supplying hexadecimal value array, 'flag' value is defualt --\n";
! 27: $temp_array = $unsorted_hex_array;
! 28: var_dump(ksort( $temp_array) ); // expecting : bool(true)
! 29: var_dump($temp_array);
! 30:
! 31: echo "\n-- Testing ksort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --\n";
! 32: $temp_array = $unsorted_hex_array;
! 33: var_dump(ksort( $temp_array, SORT_REGULAR) ); // expecting : bool(true)
! 34: var_dump($temp_array);
! 35:
! 36: echo "\n-- Testing ksort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --\n";
! 37: $temp_array = $unsorted_hex_array;
! 38: var_dump(ksort( $temp_array, SORT_NUMERIC) ); // expecting : bool(true)
! 39: var_dump($temp_array);
! 40:
! 41: echo "Done\n";
! 42: ?>
! 43: --EXPECTF--
! 44: *** Testing ksort() : usage variations ***
! 45:
! 46: -- Testing ksort() by supplying hexadecimal value array, 'flag' value is defualt --
! 47: bool(true)
! 48: array(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 ksort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --
! 70: bool(true)
! 71: array(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 ksort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --
! 93: bool(true)
! 94: array(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: }
! 114: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>