Annotation of embedaddon/php/ext/standard/tests/array/sort_basic.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test sort() function : basic functionality
! 3: --FILE--
! 4: <?php
! 5: /* Prototype : bool sort ( array &$array [, int $sort_flags] )
! 6: * Description: This function sorts an array.
! 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 sort() by providing arrays with default keys and assoc arrays
! 13: * to check the basic functionality with following flag values.
! 14: * flag value as defualt
! 15: * SORT_REGULAR - compare items normally
! 16: * SORT_NUMERIC - compare items numerically
! 17: * SORT_STRING - compare items as strings
! 18: */
! 19:
! 20: echo "*** Testing sort() : basic functionality ***\n";
! 21:
! 22: // associative array containing unsorted string values
! 23: $unsorted_strings = array( "l" => "lemon", "o" => "orange", "b" => "banana" );
! 24:
! 25: // array with default keys containing unsorted numeric values
! 26: $unsorted_numerics = array( 100, 33, 555, 22 );
! 27:
! 28: echo "\n-- Testing sort() by supplying string array, 'flag' value is defualt --\n";
! 29: $temp_array = $unsorted_strings;
! 30: var_dump( sort($temp_array) ); // expecting : bool(true)
! 31: var_dump( $temp_array);
! 32:
! 33: echo "\n-- Testing sort() by supplying numeric array, 'flag' value is defualt --\n";
! 34: $temp_array = $unsorted_numerics;
! 35: var_dump( sort($temp_array) ); // expecting : bool(true)
! 36: var_dump( $temp_array);
! 37:
! 38: echo "\n-- Testing sort() by supplying string array, 'flag' = SORT_REGULAR --\n";
! 39: $temp_array = $unsorted_strings;
! 40: var_dump( sort($temp_array, SORT_REGULAR) ); // expecting : bool(true)
! 41: var_dump( $temp_array);
! 42:
! 43: echo "\n-- Testing sort() by supplying numeric array, 'flag' = SORT_REGULAR --\n";
! 44: $temp_array = $unsorted_numerics;
! 45: var_dump( sort($temp_array, SORT_REGULAR) ); // expecting : bool(true)
! 46: var_dump( $temp_array);
! 47:
! 48: echo "\n-- Testing sort() by supplying string array, 'flag' = SORT_STRING --\n";
! 49: $temp_array = $unsorted_strings;
! 50: var_dump( sort($temp_array, SORT_STRING) ); // expecting : bool(true)
! 51: var_dump( $temp_array);
! 52:
! 53: echo "\n-- Testing sort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n";
! 54: $temp_array = $unsorted_numerics;
! 55: var_dump( sort($temp_array, SORT_NUMERIC) ); // expecting : bool(true)
! 56: var_dump( $temp_array);
! 57:
! 58: echo "Done\n";
! 59: ?>
! 60: --EXPECTF--
! 61: *** Testing sort() : basic functionality ***
! 62:
! 63: -- Testing sort() by supplying string array, 'flag' value is defualt --
! 64: bool(true)
! 65: array(3) {
! 66: [0]=>
! 67: string(6) "banana"
! 68: [1]=>
! 69: string(5) "lemon"
! 70: [2]=>
! 71: string(6) "orange"
! 72: }
! 73:
! 74: -- Testing sort() by supplying numeric array, 'flag' value is defualt --
! 75: bool(true)
! 76: array(4) {
! 77: [0]=>
! 78: int(22)
! 79: [1]=>
! 80: int(33)
! 81: [2]=>
! 82: int(100)
! 83: [3]=>
! 84: int(555)
! 85: }
! 86:
! 87: -- Testing sort() by supplying string array, 'flag' = SORT_REGULAR --
! 88: bool(true)
! 89: array(3) {
! 90: [0]=>
! 91: string(6) "banana"
! 92: [1]=>
! 93: string(5) "lemon"
! 94: [2]=>
! 95: string(6) "orange"
! 96: }
! 97:
! 98: -- Testing sort() by supplying numeric array, 'flag' = SORT_REGULAR --
! 99: bool(true)
! 100: array(4) {
! 101: [0]=>
! 102: int(22)
! 103: [1]=>
! 104: int(33)
! 105: [2]=>
! 106: int(100)
! 107: [3]=>
! 108: int(555)
! 109: }
! 110:
! 111: -- Testing sort() by supplying string array, 'flag' = SORT_STRING --
! 112: bool(true)
! 113: array(3) {
! 114: [0]=>
! 115: string(6) "banana"
! 116: [1]=>
! 117: string(5) "lemon"
! 118: [2]=>
! 119: string(6) "orange"
! 120: }
! 121:
! 122: -- Testing sort() by supplying numeric array, 'flag' = SORT_NUMERIC --
! 123: bool(true)
! 124: array(4) {
! 125: [0]=>
! 126: int(22)
! 127: [1]=>
! 128: int(33)
! 129: [2]=>
! 130: int(100)
! 131: [3]=>
! 132: int(555)
! 133: }
! 134: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>