Annotation of embedaddon/php/ext/standard/tests/array/asort_variation4.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test asort() function : usage variations - sort reference variables
! 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 reference variable array with following flag values
! 13: * flag value as defualt
! 14: * SORT_REGULAR - compare items normally
! 15: * SORT_NUMERIC - compare items numerically
! 16: */
! 17:
! 18: echo "*** Testing asort() :usage variations ***\n";
! 19:
! 20: $value1 = 100;
! 21: $value2 = 33;
! 22: $value3 = 555;
! 23:
! 24: // an array containing integer references
! 25: $unsorted_numerics = array( 1 => &$value1 , 2 => &$value2, 3 => &$value3);
! 26:
! 27: echo "\n-- Testing asort() by supplying reference variable array, 'flag' value is defualt --\n";
! 28: $temp_array = $unsorted_numerics;
! 29: var_dump( asort($temp_array) ); // expecting : bool(true)
! 30: var_dump( $temp_array);
! 31:
! 32: echo "\n-- Testing asort() by supplying reference variable array, 'flag' = SORT_REGULAR --\n";
! 33: $temp_array = &$unsorted_numerics;
! 34: var_dump( asort($temp_array, SORT_REGULAR) ); // expecting : bool(true)
! 35: var_dump( $temp_array);
! 36:
! 37: echo "\n-- Testing asort() by supplying reference variable array, 'flag' = SORT_NUMERIC --\n";
! 38: $temp_array = &$unsorted_numerics;
! 39: var_dump( asort($temp_array, SORT_NUMERIC) ); // expecting : bool(true)
! 40: var_dump( $temp_array);
! 41:
! 42: echo "Done\n";
! 43: ?>
! 44: --EXPECTF--
! 45: *** Testing asort() :usage variations ***
! 46:
! 47: -- Testing asort() by supplying reference variable array, 'flag' value is defualt --
! 48: bool(true)
! 49: array(3) {
! 50: [2]=>
! 51: &int(33)
! 52: [1]=>
! 53: &int(100)
! 54: [3]=>
! 55: &int(555)
! 56: }
! 57:
! 58: -- Testing asort() by supplying reference variable array, 'flag' = SORT_REGULAR --
! 59: bool(true)
! 60: array(3) {
! 61: [2]=>
! 62: &int(33)
! 63: [1]=>
! 64: &int(100)
! 65: [3]=>
! 66: &int(555)
! 67: }
! 68:
! 69: -- Testing asort() by supplying reference variable array, 'flag' = SORT_NUMERIC --
! 70: bool(true)
! 71: array(3) {
! 72: [2]=>
! 73: &int(33)
! 74: [1]=>
! 75: &int(100)
! 76: [3]=>
! 77: &int(555)
! 78: }
! 79: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>