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

1.1       misho       1: --TEST--
                      2: Test uasort() function : usage variations - 'cmp_function' with reference argument 
                      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: /* Testing uasort() functionality with comparison function having arguments as reference
                     11:  */
                     12: 
                     13: echo "*** Testing uasort() : 'cmp_function' with reference arguments ***\n";
                     14: 
                     15: // comparison function
                     16: /* Prototype : int cmp(mixed &$value1, mixed &$value2)
                     17:  * Parameters : $value1 and $value2 - values recieved by reference 
                     18:  * Return value : 0 - if both values are same
                     19:  *                1 - if value1 is greater than value2
                     20:  *               -1 - if value1 is less than value2
                     21:  * Description : compares value1 and value2
                     22:  */
                     23: function cmp(&$value1, &$value2)
                     24: {
                     25:   if($value1 == $value2) {
                     26:     return 0;
                     27:   }
                     28:   else if($value1 > $value2) {
                     29:     return 1;
                     30:   }
                     31:   else
                     32:     return -1;
                     33: }
                     34: 
                     35: // Int array with default keys
                     36: $int_values = array(1, 8, 9, 3, 2, 6, 7);
                     37: echo "-- Passing integer values to 'cmp_function' --\n";
                     38: var_dump( uasort($int_values, 'cmp') );
                     39: var_dump($int_values);
                     40: 
                     41: // String array with default keys
                     42: $string_values = array("Mango", "Apple", "Orange", "Banana");
                     43: echo "-- Passing string values to 'cmp_function' --\n";
                     44: var_dump( uasort($string_values, 'cmp') );
                     45: var_dump($string_values);
                     46: 
                     47: echo "Done"
                     48: ?>
                     49: --EXPECTF--
                     50: *** Testing uasort() : 'cmp_function' with reference arguments ***
                     51: -- Passing integer values to 'cmp_function' --
                     52: bool(true)
                     53: array(7) {
                     54:   [0]=>
                     55:   int(1)
                     56:   [4]=>
                     57:   int(2)
                     58:   [3]=>
                     59:   int(3)
                     60:   [5]=>
                     61:   int(6)
                     62:   [6]=>
                     63:   int(7)
                     64:   [1]=>
                     65:   int(8)
                     66:   [2]=>
                     67:   int(9)
                     68: }
                     69: -- Passing string values to 'cmp_function' --
                     70: bool(true)
                     71: array(4) {
                     72:   [1]=>
                     73:   string(5) "Apple"
                     74:   [3]=>
                     75:   string(6) "Banana"
                     76:   [0]=>
                     77:   string(5) "Mango"
                     78:   [2]=>
                     79:   string(6) "Orange"
                     80: }
                     81: Done

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