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