Return to 003.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / array |
1.1 misho 1: --TEST-- 2: Test usort, uksort and uasort 3: --INI-- 4: precision=14 5: --FILE-- 6: <?php 7: require(dirname(__FILE__) . '/data.inc'); 8: 9: function cmp ($a, $b) { 10: is_array ($a) 11: and $a = array_sum ($a); 12: is_array ($b) 13: and $b = array_sum ($b); 14: return strcmp ($a, $b); 15: } 16: 17: echo " -- Testing uasort() -- \n"; 18: uasort ($data, 'cmp'); 19: var_dump ($data); 20: 21: 22: echo "\n -- Testing uksort() -- \n"; 23: uksort ($data, 'cmp'); 24: var_dump ($data); 25: 26: echo "\n -- Testing usort() -- \n"; 27: usort ($data, 'cmp'); 28: var_dump ($data); 29: ?> 30: --EXPECT-- 31: -- Testing uasort() -- 32: array(8) { 33: [16777216]=> 34: float(-0.33333333333333) 35: [-1000]=> 36: array(2) { 37: [0]=> 38: string(6) "banana" 39: [1]=> 40: string(6) "orange" 41: } 42: ["test"]=> 43: int(27) 44: [0]=> 45: string(3) "PHP" 46: [17]=> 47: string(27) "PHP: Hypertext Preprocessor" 48: [5]=> 49: string(4) "Test" 50: [1001]=> 51: string(6) "monkey" 52: [1000]=> 53: string(4) "test" 54: } 55: 56: -- Testing uksort() -- 57: array(8) { 58: [-1000]=> 59: array(2) { 60: [0]=> 61: string(6) "banana" 62: [1]=> 63: string(6) "orange" 64: } 65: [0]=> 66: string(3) "PHP" 67: [1000]=> 68: string(4) "test" 69: [1001]=> 70: string(6) "monkey" 71: [16777216]=> 72: float(-0.33333333333333) 73: [17]=> 74: string(27) "PHP: Hypertext Preprocessor" 75: [5]=> 76: string(4) "Test" 77: ["test"]=> 78: int(27) 79: } 80: 81: -- Testing usort() -- 82: array(8) { 83: [0]=> 84: float(-0.33333333333333) 85: [1]=> 86: array(2) { 87: [0]=> 88: string(6) "banana" 89: [1]=> 90: string(6) "orange" 91: } 92: [2]=> 93: int(27) 94: [3]=> 95: string(3) "PHP" 96: [4]=> 97: string(27) "PHP: Hypertext Preprocessor" 98: [5]=> 99: string(4) "Test" 100: [6]=> 101: string(6) "monkey" 102: [7]=> 103: string(4) "test" 104: }