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