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