1--TEST-- 2Test rsort() function : usage variations - String values 3--FILE-- 4<?php 5/* 6 * Pass arrays containing different string data to rsort() to test behaviour 7 */ 8 9echo "*** Testing rsort() : variation ***\n"; 10 11$various_arrays = array ( 12// group of escape sequences 13array(null, NULL, "\a", "\cx", "\e", "\f", "\n", "\t", "\xhh", "\ddd", "\v"), 14 15// array contains combination of capital/small letters 16array("lemoN", "Orange", "banana", "apple", "Test", "TTTT", "ttt", "ww", "x", "X", "oraNGe", "BANANA") 17); 18 19$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING); 20 21$count = 1; 22// loop through to test rsort() with different arrays 23foreach ($various_arrays as $array) { 24 echo "\n-- Iteration $count --\n"; 25 26 echo "- With Default sort flag -\n"; 27 $temp_array = $array; 28 var_dump(rsort($temp_array) ); 29 var_dump($temp_array); 30 31 // loop through $flags array and setting all possible flag values 32 foreach($flags as $key => $flag){ 33 echo "- Sort flag = $key -\n"; 34 35 $temp_array = $array; 36 var_dump(rsort($temp_array, $flag) ); 37 var_dump($temp_array); 38 } 39 $count++; 40} 41 42echo "Done"; 43?> 44--EXPECT-- 45*** Testing rsort() : variation *** 46 47-- Iteration 1 -- 48- With Default sort flag - 49bool(true) 50array(11) { 51 [0]=> 52 string(4) "\xhh" 53 [1]=> 54 string(4) "\ddd" 55 [2]=> 56 string(3) "\cx" 57 [3]=> 58 string(2) "\a" 59 [4]=> 60 string(1) "" 61 [5]=> 62 string(1) "" 63 [6]=> 64 string(1) "" 65 [7]=> 66 string(1) " 67" 68 [8]=> 69 string(1) " " 70 [9]=> 71 NULL 72 [10]=> 73 NULL 74} 75- Sort flag = SORT_REGULAR - 76bool(true) 77array(11) { 78 [0]=> 79 string(4) "\xhh" 80 [1]=> 81 string(4) "\ddd" 82 [2]=> 83 string(3) "\cx" 84 [3]=> 85 string(2) "\a" 86 [4]=> 87 string(1) "" 88 [5]=> 89 string(1) "" 90 [6]=> 91 string(1) "" 92 [7]=> 93 string(1) " 94" 95 [8]=> 96 string(1) " " 97 [9]=> 98 NULL 99 [10]=> 100 NULL 101} 102- Sort flag = SORT_STRING - 103bool(true) 104array(11) { 105 [0]=> 106 string(4) "\xhh" 107 [1]=> 108 string(4) "\ddd" 109 [2]=> 110 string(3) "\cx" 111 [3]=> 112 string(2) "\a" 113 [4]=> 114 string(1) "" 115 [5]=> 116 string(1) "" 117 [6]=> 118 string(1) "" 119 [7]=> 120 string(1) " 121" 122 [8]=> 123 string(1) " " 124 [9]=> 125 NULL 126 [10]=> 127 NULL 128} 129 130-- Iteration 2 -- 131- With Default sort flag - 132bool(true) 133array(12) { 134 [0]=> 135 string(1) "x" 136 [1]=> 137 string(2) "ww" 138 [2]=> 139 string(3) "ttt" 140 [3]=> 141 string(6) "oraNGe" 142 [4]=> 143 string(5) "lemoN" 144 [5]=> 145 string(6) "banana" 146 [6]=> 147 string(5) "apple" 148 [7]=> 149 string(1) "X" 150 [8]=> 151 string(4) "Test" 152 [9]=> 153 string(4) "TTTT" 154 [10]=> 155 string(6) "Orange" 156 [11]=> 157 string(6) "BANANA" 158} 159- Sort flag = SORT_REGULAR - 160bool(true) 161array(12) { 162 [0]=> 163 string(1) "x" 164 [1]=> 165 string(2) "ww" 166 [2]=> 167 string(3) "ttt" 168 [3]=> 169 string(6) "oraNGe" 170 [4]=> 171 string(5) "lemoN" 172 [5]=> 173 string(6) "banana" 174 [6]=> 175 string(5) "apple" 176 [7]=> 177 string(1) "X" 178 [8]=> 179 string(4) "Test" 180 [9]=> 181 string(4) "TTTT" 182 [10]=> 183 string(6) "Orange" 184 [11]=> 185 string(6) "BANANA" 186} 187- Sort flag = SORT_STRING - 188bool(true) 189array(12) { 190 [0]=> 191 string(1) "x" 192 [1]=> 193 string(2) "ww" 194 [2]=> 195 string(3) "ttt" 196 [3]=> 197 string(6) "oraNGe" 198 [4]=> 199 string(5) "lemoN" 200 [5]=> 201 string(6) "banana" 202 [6]=> 203 string(5) "apple" 204 [7]=> 205 string(1) "X" 206 [8]=> 207 string(4) "Test" 208 [9]=> 209 string(4) "TTTT" 210 [10]=> 211 string(6) "Orange" 212 [11]=> 213 string(6) "BANANA" 214} 215Done 216