Annotation of embedaddon/php/ext/standard/tests/array/ksort_variation10.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test ksort() function : usage variations - sort octal 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 octal 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 containing unsorted octal values
! 20: $unsorted_oct_array = array (
! 21: 01235 => 01, 0321 => 02, 0345 => 03, 066 => 04, 0772 => 05,
! 22: 077 => 06, -066 => -01, -0345 => -02, 0 => 0
! 23: );
! 24:
! 25: echo "\n-- Testing ksort() by supplying octal value array, 'flag' value is defualt --\n";
! 26: $temp_array = $unsorted_oct_array;
! 27: var_dump( ksort($temp_array) ); // expecting : bool(true)
! 28: var_dump($temp_array);
! 29:
! 30: echo "\n-- Testing ksort() by supplying octal value array, 'flag' value is SORT_REGULAR --\n";
! 31: $temp_array = $unsorted_oct_array;
! 32: var_dump( ksort($temp_array, SORT_REGULAR) ); // expecting : bool(true)
! 33: var_dump($temp_array);
! 34:
! 35: echo "\n-- Testing ksort() by supplying octal value array, 'flag' value is SORT_NUMERIC --\n";
! 36: $temp_array = $unsorted_oct_array;
! 37: var_dump( ksort($temp_array, SORT_NUMERIC) ); // expecting : bool(true)
! 38: var_dump($temp_array);
! 39:
! 40: echo "Done\n";
! 41: ?>
! 42: --EXPECTF--
! 43: *** Testing ksort() : usage variations ***
! 44:
! 45: -- Testing ksort() by supplying octal value array, 'flag' value is defualt --
! 46: bool(true)
! 47: array(9) {
! 48: [-229]=>
! 49: int(-2)
! 50: [-54]=>
! 51: int(-1)
! 52: [0]=>
! 53: int(0)
! 54: [54]=>
! 55: int(4)
! 56: [63]=>
! 57: int(6)
! 58: [209]=>
! 59: int(2)
! 60: [229]=>
! 61: int(3)
! 62: [506]=>
! 63: int(5)
! 64: [669]=>
! 65: int(1)
! 66: }
! 67:
! 68: -- Testing ksort() by supplying octal value array, 'flag' value is SORT_REGULAR --
! 69: bool(true)
! 70: array(9) {
! 71: [-229]=>
! 72: int(-2)
! 73: [-54]=>
! 74: int(-1)
! 75: [0]=>
! 76: int(0)
! 77: [54]=>
! 78: int(4)
! 79: [63]=>
! 80: int(6)
! 81: [209]=>
! 82: int(2)
! 83: [229]=>
! 84: int(3)
! 85: [506]=>
! 86: int(5)
! 87: [669]=>
! 88: int(1)
! 89: }
! 90:
! 91: -- Testing ksort() by supplying octal value array, 'flag' value is SORT_NUMERIC --
! 92: bool(true)
! 93: array(9) {
! 94: [-229]=>
! 95: int(-2)
! 96: [-54]=>
! 97: int(-1)
! 98: [0]=>
! 99: int(0)
! 100: [54]=>
! 101: int(4)
! 102: [63]=>
! 103: int(6)
! 104: [209]=>
! 105: int(2)
! 106: [229]=>
! 107: int(3)
! 108: [506]=>
! 109: int(5)
! 110: [669]=>
! 111: int(1)
! 112: }
! 113: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>