Annotation of embedaddon/php/ext/standard/tests/array/arsort_variation4.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test arsort() function : usage variations - sort reference variables   
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : bool arsort ( array &$array [, int $sort_flags] )
                      6:  * Description: Sort an array and maintain index association. 
                      7:                 Elements will be arranged from highest to lowest when this function has completed.
                      8:  * Source code: ext/standard/array.c
                      9: */
                     10: 
                     11: /*
                     12:  * Testing arsort() 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 arsort() :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 arsort() by supplying reference variable array, 'flag' value is defualt --\n";
                     28: $temp_array = $unsorted_numerics;
                     29: var_dump( arsort($temp_array) ); // expecting : bool(true)
                     30: var_dump( $temp_array);
                     31: 
                     32: echo "\n-- Testing arsort() by supplying reference variable array, 'flag' = SORT_REGULAR --\n";
                     33: $temp_array = &$unsorted_numerics;
                     34: var_dump( arsort($temp_array, SORT_REGULAR) ); // expecting : bool(true)
                     35: var_dump( $temp_array);
                     36: 
                     37: echo "\n-- Testing arsort() by supplying reference variable array, 'flag' = SORT_NUMERIC --\n";
                     38: $temp_array = &$unsorted_numerics;
                     39: var_dump( arsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true)
                     40: var_dump( $temp_array);
                     41: 
                     42: echo "Done\n";
                     43: ?>
                     44: --EXPECTF--
                     45: *** Testing arsort() :usage variations  ***
                     46: 
                     47: -- Testing arsort() by supplying reference variable array, 'flag' value is defualt --
                     48: bool(true)
                     49: array(3) {
                     50:   [3]=>
                     51:   &int(555)
                     52:   [1]=>
                     53:   &int(100)
                     54:   [2]=>
                     55:   &int(33)
                     56: }
                     57: 
                     58: -- Testing arsort() by supplying reference variable array, 'flag' = SORT_REGULAR --
                     59: bool(true)
                     60: array(3) {
                     61:   [3]=>
                     62:   &int(555)
                     63:   [1]=>
                     64:   &int(100)
                     65:   [2]=>
                     66:   &int(33)
                     67: }
                     68: 
                     69: -- Testing arsort() by supplying reference variable array, 'flag' = SORT_NUMERIC --
                     70: bool(true)
                     71: array(3) {
                     72:   [3]=>
                     73:   &int(555)
                     74:   [1]=>
                     75:   &int(100)
                     76:   [2]=>
                     77:   &int(33)
                     78: }
                     79: Done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>