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