1--TEST-- 2Test sort() function : usage variations - sort array with diff. sub arrays, 'sort_flags' as defualt/SORT_REGULAR 3--FILE-- 4<?php 5/* Prototype : bool sort ( array &$array [, int $sort_flags] ) 6 * Description: This function sorts an array. 7 Elements will be arranged from lowest to highest when this function has completed. 8 * Source code: ext/standard/array.c 9*/ 10 11/* 12 * testing sort() by providing arrays contains sub arrays for $array argument with flowing flag values 13 * flag value as defualt 14 * SORT_REGULAR - compare items normally 15*/ 16 17echo "*** Testing sort() : usage variations ***\n"; 18 19// array of arrays 20$various_arrays = array ( 21 // null array 22 array(), 23 24 // array contains null sub array 25 array( array() ), 26 27 // array of arrays along with some values 28 array(44, 11, array(64, 61) ), 29 30 // array containing sub arrays 31 array(array(33, -5, 6), array(11), array(22, -55), array() ) 32); 33 34 35$count = 1; 36echo "\n-- Testing sort() by supplying various arrays containing sub arrays --\n"; 37 38// loop through to test sort() with different arrays 39foreach ($various_arrays as $array) { 40 41 echo "\n-- Iteration $count --\n"; 42 // testing sort() function by supplying different arrays, flag value is defualt 43 echo "- With Defualt sort flag -\n"; 44 $temp_array = $array; 45 var_dump(sort($temp_array) ); 46 var_dump($temp_array); 47 48 // testing sort() function by supplying different arrays, flag value = SORT_REGULAR 49 echo "- Sort flag = SORT_REGULAR -\n"; 50 $temp_array = $array; 51 var_dump(sort($temp_array, SORT_REGULAR) ); 52 var_dump($temp_array); 53 $count++; 54} 55 56echo "Done\n"; 57?> 58--EXPECT-- 59*** Testing sort() : usage variations *** 60 61-- Testing sort() by supplying various arrays containing sub arrays -- 62 63-- Iteration 1 -- 64- With Defualt sort flag - 65bool(true) 66array(0) { 67} 68- Sort flag = SORT_REGULAR - 69bool(true) 70array(0) { 71} 72 73-- Iteration 2 -- 74- With Defualt sort flag - 75bool(true) 76array(1) { 77 [0]=> 78 array(0) { 79 } 80} 81- Sort flag = SORT_REGULAR - 82bool(true) 83array(1) { 84 [0]=> 85 array(0) { 86 } 87} 88 89-- Iteration 3 -- 90- With Defualt sort flag - 91bool(true) 92array(3) { 93 [0]=> 94 int(11) 95 [1]=> 96 int(44) 97 [2]=> 98 array(2) { 99 [0]=> 100 int(64) 101 [1]=> 102 int(61) 103 } 104} 105- Sort flag = SORT_REGULAR - 106bool(true) 107array(3) { 108 [0]=> 109 int(11) 110 [1]=> 111 int(44) 112 [2]=> 113 array(2) { 114 [0]=> 115 int(64) 116 [1]=> 117 int(61) 118 } 119} 120 121-- Iteration 4 -- 122- With Defualt sort flag - 123bool(true) 124array(4) { 125 [0]=> 126 array(0) { 127 } 128 [1]=> 129 array(1) { 130 [0]=> 131 int(11) 132 } 133 [2]=> 134 array(2) { 135 [0]=> 136 int(22) 137 [1]=> 138 int(-55) 139 } 140 [3]=> 141 array(3) { 142 [0]=> 143 int(33) 144 [1]=> 145 int(-5) 146 [2]=> 147 int(6) 148 } 149} 150- Sort flag = SORT_REGULAR - 151bool(true) 152array(4) { 153 [0]=> 154 array(0) { 155 } 156 [1]=> 157 array(1) { 158 [0]=> 159 int(11) 160 } 161 [2]=> 162 array(2) { 163 [0]=> 164 int(22) 165 [1]=> 166 int(-55) 167 } 168 [3]=> 169 array(3) { 170 [0]=> 171 int(33) 172 [1]=> 173 int(-5) 174 [2]=> 175 int(6) 176 } 177} 178Done 179