1--TEST-- 2Test rsort() function : basic functionality 3--FILE-- 4<?php 5/* 6 * Test basic functionality of rsort() 7 */ 8 9echo "*** Testing rsort() : basic functionality ***\n"; 10 11// associative array containing unsorted string values 12$unsorted_strings = array( 13 "l" => "lemon", "o" => "orange", 14 "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20", 15 "b" => "banana", 16); 17 18// array with default keys containing unsorted numeric values 19$unsorted_numerics = array( 100, 33, 555, 22 ); 20 21echo "\n-- Testing rsort() by supplying string array, 'flag' value is default --\n"; 22$temp_array = $unsorted_strings; 23var_dump( rsort($temp_array) ); 24var_dump( $temp_array); 25 26echo "\n-- Testing rsort() by supplying numeric array, 'flag' value is default --\n"; 27$temp_array = $unsorted_numerics; 28var_dump( rsort($temp_array) ); 29var_dump( $temp_array); 30 31echo "\n-- Testing rsort() by supplying string array, 'flag' = SORT_REGULAR --\n"; 32$temp_array = $unsorted_strings; 33var_dump( rsort($temp_array, SORT_REGULAR) ); 34var_dump( $temp_array); 35 36echo "\n-- Testing rsort() by supplying numeric array, 'flag' = SORT_REGULAR --\n"; 37$temp_array = $unsorted_numerics; 38var_dump( rsort($temp_array, SORT_REGULAR) ); 39var_dump( $temp_array); 40 41echo "\n-- Testing rsort() by supplying string array, 'flag' = SORT_STRING --\n"; 42$temp_array = $unsorted_strings; 43var_dump( rsort($temp_array, SORT_STRING) ); 44var_dump( $temp_array); 45 46echo "\n-- Testing rsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n"; 47$temp_array = $unsorted_strings; 48var_dump( rsort($temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true) 49var_dump( $temp_array); 50 51echo "\n-- Testing rsort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n"; 52$temp_array = $unsorted_strings; 53var_dump( rsort($temp_array, SORT_NATURAL) ); // expecting : bool(true) 54var_dump( $temp_array); 55 56echo "\n-- Testing rsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n"; 57$temp_array = $unsorted_strings; 58var_dump( rsort($temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true) 59var_dump( $temp_array); 60 61echo "\n-- Testing rsort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n"; 62$temp_array = $unsorted_numerics; 63var_dump( rsort($temp_array, SORT_NUMERIC) ); 64var_dump( $temp_array); 65 66echo "Done"; 67?> 68--EXPECT-- 69*** Testing rsort() : basic functionality *** 70 71-- Testing rsort() by supplying string array, 'flag' value is default -- 72bool(true) 73array(8) { 74 [0]=> 75 string(8) "orange20" 76 [1]=> 77 string(7) "orange2" 78 [2]=> 79 string(6) "orange" 80 [3]=> 81 string(5) "lemon" 82 [4]=> 83 string(6) "banana" 84 [5]=> 85 string(7) "Orange3" 86 [6]=> 87 string(7) "Orange1" 88 [7]=> 89 string(6) "Orange" 90} 91 92-- Testing rsort() by supplying numeric array, 'flag' value is default -- 93bool(true) 94array(4) { 95 [0]=> 96 int(555) 97 [1]=> 98 int(100) 99 [2]=> 100 int(33) 101 [3]=> 102 int(22) 103} 104 105-- Testing rsort() by supplying string array, 'flag' = SORT_REGULAR -- 106bool(true) 107array(8) { 108 [0]=> 109 string(8) "orange20" 110 [1]=> 111 string(7) "orange2" 112 [2]=> 113 string(6) "orange" 114 [3]=> 115 string(5) "lemon" 116 [4]=> 117 string(6) "banana" 118 [5]=> 119 string(7) "Orange3" 120 [6]=> 121 string(7) "Orange1" 122 [7]=> 123 string(6) "Orange" 124} 125 126-- Testing rsort() by supplying numeric array, 'flag' = SORT_REGULAR -- 127bool(true) 128array(4) { 129 [0]=> 130 int(555) 131 [1]=> 132 int(100) 133 [2]=> 134 int(33) 135 [3]=> 136 int(22) 137} 138 139-- Testing rsort() by supplying string array, 'flag' = SORT_STRING -- 140bool(true) 141array(8) { 142 [0]=> 143 string(8) "orange20" 144 [1]=> 145 string(7) "orange2" 146 [2]=> 147 string(6) "orange" 148 [3]=> 149 string(5) "lemon" 150 [4]=> 151 string(6) "banana" 152 [5]=> 153 string(7) "Orange3" 154 [6]=> 155 string(7) "Orange1" 156 [7]=> 157 string(6) "Orange" 158} 159 160-- Testing rsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE -- 161bool(true) 162array(8) { 163 [0]=> 164 string(7) "Orange3" 165 [1]=> 166 string(8) "orange20" 167 [2]=> 168 string(7) "orange2" 169 [3]=> 170 string(7) "Orange1" 171 [4]=> 172 string(6) "orange" 173 [5]=> 174 string(6) "Orange" 175 [6]=> 176 string(5) "lemon" 177 [7]=> 178 string(6) "banana" 179} 180 181-- Testing rsort() by supplying string array (natural), 'flag' = SORT_NATURAL -- 182bool(true) 183array(8) { 184 [0]=> 185 string(8) "orange20" 186 [1]=> 187 string(7) "orange2" 188 [2]=> 189 string(6) "orange" 190 [3]=> 191 string(5) "lemon" 192 [4]=> 193 string(6) "banana" 194 [5]=> 195 string(7) "Orange3" 196 [6]=> 197 string(7) "Orange1" 198 [7]=> 199 string(6) "Orange" 200} 201 202-- Testing rsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE -- 203bool(true) 204array(8) { 205 [0]=> 206 string(8) "orange20" 207 [1]=> 208 string(7) "Orange3" 209 [2]=> 210 string(7) "orange2" 211 [3]=> 212 string(7) "Orange1" 213 [4]=> 214 string(6) "orange" 215 [5]=> 216 string(6) "Orange" 217 [6]=> 218 string(5) "lemon" 219 [7]=> 220 string(6) "banana" 221} 222 223-- Testing rsort() by supplying numeric array, 'flag' = SORT_NUMERIC -- 224bool(true) 225array(4) { 226 [0]=> 227 int(555) 228 [1]=> 229 int(100) 230 [2]=> 231 int(33) 232 [3]=> 233 int(22) 234} 235Done 236