1--TEST-- 2Test arsort() function : usage variations - sort mixed values, 'sort_flags' as default/SORT_REGULAR (OK to fail as result is unpredectable) 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 mixed value array for $array argument with following flag values. 13 * 1.flag value as default 14 * 2.SORT_REGULAR - compare items normally 15*/ 16 17echo "*** Testing arsort() : usage variations ***\n"; 18 19// mixed value array with different key values 20$mixed_values = array ( 21 "array1" => array(), 22 "array2" => array ( "sub_array[2,1]" => array(33,-5,6), "sub_array[2,2]" => array(11), 23 "sub_array[2,3]" => array(22,-55), "sub_array[2,4]" => array() 24 ), 25 4 => 4, "4" => "4", 4.01 => 4.01, "b" => "b", "5" => "5", -2 => -2, -2.01 => -2.01, 26 -2.98989 => -2.98989, "-.9" => "-.9", "True" => "True", "" => "", NULL => NULL, 27 "ab" => "ab", "abcd" => "abcd", 0.01 => 0.01, -0 => -0, '' => '' , 28 "abcd\x00abcd\x00abcd" => "abcd\x00abcd\x00abcd", 0.001 => 0.001 29); 30 31echo "\n-- Testing arsort() by supplying mixed value array, 'flag' value is default --\n"; 32$temp_array = $mixed_values; 33var_dump( arsort($temp_array) ); 34var_dump($temp_array); 35 36echo "\n-- Testing arsort() by supplying mixed value array, 'flag' value is SORT_REGULAR --\n"; 37$temp_array = $mixed_values; 38var_dump( arsort($temp_array, SORT_REGULAR) ); 39var_dump($temp_array); 40 41echo "Done\n"; 42?> 43--EXPECTF-- 44*** Testing arsort() : usage variations *** 45 46-- Testing arsort() by supplying mixed value array, 'flag' value is default -- 47bool(true) 48array(13) { 49 ["array2"]=> 50 array(4) { 51 ["sub_array[2,1]"]=> 52 array(3) { 53 [0]=> 54 int(33) 55 [1]=> 56 int(-5) 57 [2]=> 58 int(6) 59 } 60 ["sub_array[2,2]"]=> 61 array(1) { 62 [0]=> 63 int(11) 64 } 65 ["sub_array[2,3]"]=> 66 array(2) { 67 [0]=> 68 int(22) 69 [1]=> 70 int(-55) 71 } 72 ["sub_array[2,4]"]=> 73 array(0) { 74 } 75 } 76 ["array1"]=> 77 array(0) { 78 } 79 ["b"]=> 80 string(1) "b" 81 ["abcdabcdabcd"]=> 82 string(14) "abcdabcdabcd" 83 ["abcd"]=> 84 string(4) "abcd" 85 ["ab"]=> 86 string(2) "ab" 87 ["True"]=> 88 string(4) "True" 89 [5]=> 90 string(1) "5" 91 [4]=> 92 float(4.01) 93 [0]=> 94 float(0.001) 95 ["-.9"]=> 96 string(3) "-.9" 97 [""]=> 98 string(0) "" 99 [-2]=> 100 float(-2.98989) 101} 102 103-- Testing arsort() by supplying mixed value array, 'flag' value is SORT_REGULAR -- 104bool(true) 105array(13) { 106 ["array2"]=> 107 array(4) { 108 ["sub_array[2,1]"]=> 109 array(3) { 110 [0]=> 111 int(33) 112 [1]=> 113 int(-5) 114 [2]=> 115 int(6) 116 } 117 ["sub_array[2,2]"]=> 118 array(1) { 119 [0]=> 120 int(11) 121 } 122 ["sub_array[2,3]"]=> 123 array(2) { 124 [0]=> 125 int(22) 126 [1]=> 127 int(-55) 128 } 129 ["sub_array[2,4]"]=> 130 array(0) { 131 } 132 } 133 ["array1"]=> 134 array(0) { 135 } 136 ["b"]=> 137 string(1) "b" 138 ["abcdabcdabcd"]=> 139 string(14) "abcdabcdabcd" 140 ["abcd"]=> 141 string(4) "abcd" 142 ["ab"]=> 143 string(2) "ab" 144 ["True"]=> 145 string(4) "True" 146 [5]=> 147 string(1) "5" 148 [4]=> 149 float(4.01) 150 [0]=> 151 float(0.001) 152 ["-.9"]=> 153 string(3) "-.9" 154 [""]=> 155 string(0) "" 156 [-2]=> 157 float(-2.98989) 158} 159Done