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