1--TEST-- 2Test asort() function : usage variations - sorting arrays with/without keys, 'sort_flags' as default/SORT_REGULAR 3--FILE-- 4<?php 5/* 6 * Testing asort() by providing arrays with key values for $array argument with following flag values. 7 * 1.flag value as default 8 * 2.SORT_REGULAR - compare items normally 9 */ 10 11echo "*** Testing asort() : usage variations ***\n"; 12 13// list of arrays with/without key values 14$various_arrays = array ( 15 array(5 => 55, 66, 22, 33, 11), 16 array ("a" => "orange", "banana", "c" => "apple"), 17 array(1, 2, 3, 4, 5, 6), 18 array("first", 5 => "second", "third"), 19 array(1, 1, 8 => 1, 4 => 1, 19, 3 => 13), 20 array('bar' => 'baz', "foo" => 1), 21 array('a'=>1,'b'=>array('e'=>2,'f'=>3),'c'=>array('g'=>4),'d'=>5), 22); 23 24$count = 1; 25echo "\n-- Testing asort() by supplying various arrays with key values --\n"; 26 27// loop through to test asort() with different arrays, 28// to test the new keys for the elements in the sorted array 29foreach ($various_arrays as $array) { 30 echo "\n-- Iteration $count --\n"; 31 32 echo "- With default sort_flag -\n"; 33 $temp_array = $array; 34 var_dump(asort($temp_array) ); 35 var_dump($temp_array); 36 37 echo "- Sort_flag = SORT_REGULAR -\n"; 38 $temp_array = $array; 39 var_dump(asort($temp_array, SORT_REGULAR) ); 40 var_dump($temp_array); 41 $count++; 42} 43 44echo "Done\n"; 45?> 46--EXPECT-- 47*** Testing asort() : usage variations *** 48 49-- Testing asort() by supplying various arrays with key values -- 50 51-- Iteration 1 -- 52- With default sort_flag - 53bool(true) 54array(5) { 55 [9]=> 56 int(11) 57 [7]=> 58 int(22) 59 [8]=> 60 int(33) 61 [5]=> 62 int(55) 63 [6]=> 64 int(66) 65} 66- Sort_flag = SORT_REGULAR - 67bool(true) 68array(5) { 69 [9]=> 70 int(11) 71 [7]=> 72 int(22) 73 [8]=> 74 int(33) 75 [5]=> 76 int(55) 77 [6]=> 78 int(66) 79} 80 81-- Iteration 2 -- 82- With default sort_flag - 83bool(true) 84array(3) { 85 ["c"]=> 86 string(5) "apple" 87 [0]=> 88 string(6) "banana" 89 ["a"]=> 90 string(6) "orange" 91} 92- Sort_flag = SORT_REGULAR - 93bool(true) 94array(3) { 95 ["c"]=> 96 string(5) "apple" 97 [0]=> 98 string(6) "banana" 99 ["a"]=> 100 string(6) "orange" 101} 102 103-- Iteration 3 -- 104- With default sort_flag - 105bool(true) 106array(6) { 107 [0]=> 108 int(1) 109 [1]=> 110 int(2) 111 [2]=> 112 int(3) 113 [3]=> 114 int(4) 115 [4]=> 116 int(5) 117 [5]=> 118 int(6) 119} 120- Sort_flag = SORT_REGULAR - 121bool(true) 122array(6) { 123 [0]=> 124 int(1) 125 [1]=> 126 int(2) 127 [2]=> 128 int(3) 129 [3]=> 130 int(4) 131 [4]=> 132 int(5) 133 [5]=> 134 int(6) 135} 136 137-- Iteration 4 -- 138- With default sort_flag - 139bool(true) 140array(3) { 141 [0]=> 142 string(5) "first" 143 [5]=> 144 string(6) "second" 145 [6]=> 146 string(5) "third" 147} 148- Sort_flag = SORT_REGULAR - 149bool(true) 150array(3) { 151 [0]=> 152 string(5) "first" 153 [5]=> 154 string(6) "second" 155 [6]=> 156 string(5) "third" 157} 158 159-- Iteration 5 -- 160- With default sort_flag - 161bool(true) 162array(6) { 163 [0]=> 164 int(1) 165 [1]=> 166 int(1) 167 [8]=> 168 int(1) 169 [4]=> 170 int(1) 171 [3]=> 172 int(13) 173 [9]=> 174 int(19) 175} 176- Sort_flag = SORT_REGULAR - 177bool(true) 178array(6) { 179 [0]=> 180 int(1) 181 [1]=> 182 int(1) 183 [8]=> 184 int(1) 185 [4]=> 186 int(1) 187 [3]=> 188 int(13) 189 [9]=> 190 int(19) 191} 192 193-- Iteration 6 -- 194- With default sort_flag - 195bool(true) 196array(2) { 197 ["foo"]=> 198 int(1) 199 ["bar"]=> 200 string(3) "baz" 201} 202- Sort_flag = SORT_REGULAR - 203bool(true) 204array(2) { 205 ["foo"]=> 206 int(1) 207 ["bar"]=> 208 string(3) "baz" 209} 210 211-- Iteration 7 -- 212- With default sort_flag - 213bool(true) 214array(4) { 215 ["a"]=> 216 int(1) 217 ["d"]=> 218 int(5) 219 ["c"]=> 220 array(1) { 221 ["g"]=> 222 int(4) 223 } 224 ["b"]=> 225 array(2) { 226 ["e"]=> 227 int(2) 228 ["f"]=> 229 int(3) 230 } 231} 232- Sort_flag = SORT_REGULAR - 233bool(true) 234array(4) { 235 ["a"]=> 236 int(1) 237 ["d"]=> 238 int(5) 239 ["c"]=> 240 array(1) { 241 ["g"]=> 242 int(4) 243 } 244 ["b"]=> 245 array(2) { 246 ["e"]=> 247 int(2) 248 ["f"]=> 249 int(3) 250 } 251} 252Done 253