1--TEST-- 2Test ksort() function : usage variations - sort array with diff. sub arrays 3--FILE-- 4<?php 5/* 6 * testing ksort() by providing arrays containing sub arrays for $array argument 7 * with flowing flag values: 8 * 1. flag value as default 9 * 2. SORT_REGULAR - compare items normally 10*/ 11 12echo "*** Testing ksort() : usage variations ***\n"; 13 14// array with diff sub arrays to be sorted 15$various_arrays = array ( 16 // null array 17 1 => array(), 18 19 // array contains null sub array 20 2 => array( 1 => array() ), 21 22 // array of arrays along with some values 23 3 => array(4 => 44, 1 => 11, 3 => array(64,61) ), 24 25 // array contains sub arrays 26 4 => array ( 3 => array(33,-5,6), 1 => array(11), 27 2 => array(22,-55), 0 => array() ) 28); 29 30 31$count = 1; 32echo "\n-- Testing ksort() by supplying various arrays containing sub arrays --\n"; 33 34// loop through to test ksort() with different arrays 35foreach ($various_arrays as $array) { 36 37 echo "\n-- Iteration $count --\n"; 38 echo "- With default sort flag -\n"; 39 $temp_array = $array; 40 var_dump( ksort($temp_array) ); 41 var_dump($temp_array); 42 43 echo "- Sort flag = SORT_REGULAR -\n"; 44 $temp_array = $array; 45 var_dump( ksort($temp_array, SORT_REGULAR) ); 46 var_dump($temp_array); 47 $count++; 48} 49 50echo "Done\n"; 51?> 52--EXPECT-- 53*** Testing ksort() : usage variations *** 54 55-- Testing ksort() 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 [1]=> 72 array(0) { 73 } 74} 75- Sort flag = SORT_REGULAR - 76bool(true) 77array(1) { 78 [1]=> 79 array(0) { 80 } 81} 82 83-- Iteration 3 -- 84- With default sort flag - 85bool(true) 86array(3) { 87 [1]=> 88 int(11) 89 [3]=> 90 array(2) { 91 [0]=> 92 int(64) 93 [1]=> 94 int(61) 95 } 96 [4]=> 97 int(44) 98} 99- Sort flag = SORT_REGULAR - 100bool(true) 101array(3) { 102 [1]=> 103 int(11) 104 [3]=> 105 array(2) { 106 [0]=> 107 int(64) 108 [1]=> 109 int(61) 110 } 111 [4]=> 112 int(44) 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