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