Annotation of embedaddon/php/ext/standard/tests/array/uasort_basic2.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test uasort() function : basic functionality - duplicate values
        !             3: --FILE--
        !             4: <?php
        !             5: /* Prototype  : bool uasort(array $array_arg, string $cmp_function)
        !             6:  * Description: Sort an array with a user-defined comparison function and maintain index association 
        !             7:  * Source code: ext/standard/array.c
        !             8: */
        !             9: 
        !            10: echo "*** Testing uasort() : basic functionality with duplicate values ***\n";
        !            11: 
        !            12: // comparison function
        !            13: /* Prototype : int cmp(mixed $value1, mixed $value2)
        !            14:  * Parameters : $value1 and $value2 - values to be compared
        !            15:  * Return value : 0 - if both values are same
        !            16:  *                1 - if value1 is greater than value2
        !            17:  *               -1 - if value1 is less than value2
        !            18:  * Description : compares value1 and value2
        !            19:  */
        !            20: function cmp($value1, $value2)
        !            21: {
        !            22:   if($value1 == $value2) {
        !            23:     return 0;
        !            24:   }
        !            25:   else if($value1 > $value2) {
        !            26:     return 1;
        !            27:   }
        !            28:   else
        !            29:     return -1;
        !            30: }
        !            31: 
        !            32: // increasing values
        !            33: $int_values1 = array(1, 1, 2, 2, 3, 3);
        !            34: echo "-- Numeric array with increasing values --\n";
        !            35: var_dump( uasort($int_values1, 'cmp') );
        !            36: var_dump($int_values1);
        !            37: 
        !            38: // decreasing values
        !            39: $int_values2 = array(3, 3, 2, 2, 1, 1);
        !            40: echo "-- Numeric array with decreasing values --\n";
        !            41: var_dump( uasort($int_values2, 'cmp') );
        !            42: var_dump($int_values2);
        !            43: 
        !            44: // increasing and decreasing values
        !            45: $int_values3 = array(1, 2, 3, 3, 2, 1);
        !            46: echo "-- Numeric array with increasing and decreasing values --\n";
        !            47: var_dump( uasort($int_values3, 'cmp') );
        !            48: var_dump($int_values3);
        !            49: 
        !            50: echo "Done"
        !            51: ?>
        !            52: --EXPECTF--
        !            53: *** Testing uasort() : basic functionality with duplicate values ***
        !            54: -- Numeric array with increasing values --
        !            55: bool(true)
        !            56: array(6) {
        !            57:   [0]=>
        !            58:   int(1)
        !            59:   [1]=>
        !            60:   int(1)
        !            61:   [3]=>
        !            62:   int(2)
        !            63:   [2]=>
        !            64:   int(2)
        !            65:   [5]=>
        !            66:   int(3)
        !            67:   [4]=>
        !            68:   int(3)
        !            69: }
        !            70: -- Numeric array with decreasing values --
        !            71: bool(true)
        !            72: array(6) {
        !            73:   [4]=>
        !            74:   int(1)
        !            75:   [5]=>
        !            76:   int(1)
        !            77:   [3]=>
        !            78:   int(2)
        !            79:   [2]=>
        !            80:   int(2)
        !            81:   [1]=>
        !            82:   int(3)
        !            83:   [0]=>
        !            84:   int(3)
        !            85: }
        !            86: -- Numeric array with increasing and decreasing values --
        !            87: bool(true)
        !            88: array(6) {
        !            89:   [5]=>
        !            90:   int(1)
        !            91:   [0]=>
        !            92:   int(1)
        !            93:   [1]=>
        !            94:   int(2)
        !            95:   [4]=>
        !            96:   int(2)
        !            97:   [2]=>
        !            98:   int(3)
        !            99:   [3]=>
        !           100:   int(3)
        !           101: }
        !           102: Done

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