Annotation of embedaddon/php/ext/standard/tests/array/uasort_variation6.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test uasort() function : usage variations - sort array having subarrays
! 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: /*
! 11: * Testing uasort() with 'array_arg' having different subarrays as array elements
! 12: */
! 13:
! 14: // comparison function
! 15: /* Prototype : int cmp_function(mixed $value1, mixed $value2)
! 16: * Parameters : $value1 and $value2 - values to be compared
! 17: * Return value : 0 - if both values are same
! 18: * 1 - if value1 is greater than value2
! 19: * -1 - if value1 is less than value2
! 20: * Description : compares value1 and value2
! 21: */
! 22: function cmp_function($value1, $value2)
! 23: {
! 24: if($value1 == $value2) {
! 25: return 0;
! 26: }
! 27: else if($value1 > $value2) {
! 28: return 1;
! 29: }
! 30: else {
! 31: return -1;
! 32: }
! 33: }
! 34:
! 35: echo "*** Testing uasort() : sorting array having different subarrays ***\n";
! 36:
! 37: $array_args = array(
! 38: 0 => array(2, 10, -1),
! 39: 1 => array(100),
! 40: 2 => array(),
! 41: 3 => array(0),
! 42: 4 => array(-1),
! 43: 5 => array(-9, 34, 54, 0, 20),
! 44: 6 => array(''),
! 45: 7 => array("apple", "Apple", "APPLE", "aPPle", "aPpLe")
! 46: );
! 47: $temp_array = $array_args;
! 48: // sorting array_arg as whole array
! 49: var_dump( uasort($temp_array, 'cmp_function') ); // expecting: bool(true)
! 50: var_dump($temp_array);
! 51:
! 52: ?>
! 53: --EXPECTF--
! 54: *** Testing uasort() : sorting array having different subarrays ***
! 55: bool(true)
! 56: array(8) {
! 57: [2]=>
! 58: array(0) {
! 59: }
! 60: [4]=>
! 61: array(1) {
! 62: [0]=>
! 63: int(-1)
! 64: }
! 65: [6]=>
! 66: array(1) {
! 67: [0]=>
! 68: string(0) ""
! 69: }
! 70: [3]=>
! 71: array(1) {
! 72: [0]=>
! 73: int(0)
! 74: }
! 75: [1]=>
! 76: array(1) {
! 77: [0]=>
! 78: int(100)
! 79: }
! 80: [0]=>
! 81: array(3) {
! 82: [0]=>
! 83: int(2)
! 84: [1]=>
! 85: int(10)
! 86: [2]=>
! 87: int(-1)
! 88: }
! 89: [5]=>
! 90: array(5) {
! 91: [0]=>
! 92: int(-9)
! 93: [1]=>
! 94: int(34)
! 95: [2]=>
! 96: int(54)
! 97: [3]=>
! 98: int(0)
! 99: [4]=>
! 100: int(20)
! 101: }
! 102: [7]=>
! 103: array(5) {
! 104: [0]=>
! 105: string(5) "apple"
! 106: [1]=>
! 107: string(5) "Apple"
! 108: [2]=>
! 109: string(5) "APPLE"
! 110: [3]=>
! 111: string(5) "aPPle"
! 112: [4]=>
! 113: string(5) "aPpLe"
! 114: }
! 115: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>