1--TEST-- 2Test krsort() function : usage variations - sort array with diff. sub arrays 3--FILE-- 4<?php 5/* 6 * testing krsort() by providing arrays contains 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 krsort() : 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 krsort() by supplying various arrays containing sub arrays --\n"; 33 34// loop through to test krsort() 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( krsort($temp_array) ); 41 var_dump($temp_array); 42 43 echo "- Sort flag = SORT_REGULAR -\n"; 44 $temp_array = $array; 45 var_dump( krsort($temp_array, SORT_REGULAR) ); 46 var_dump($temp_array); 47 $count++; 48} 49 50echo "Done\n"; 51?> 52--EXPECT-- 53*** Testing krsort() : usage variations *** 54 55-- Testing krsort() 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 [4]=> 88 int(44) 89 [3]=> 90 array(2) { 91 [0]=> 92 int(64) 93 [1]=> 94 int(61) 95 } 96 [1]=> 97 int(11) 98} 99- Sort flag = SORT_REGULAR - 100bool(true) 101array(3) { 102 [4]=> 103 int(44) 104 [3]=> 105 array(2) { 106 [0]=> 107 int(64) 108 [1]=> 109 int(61) 110 } 111 [1]=> 112 int(11) 113} 114 115-- Iteration 4 -- 116- With default sort flag - 117bool(true) 118array(4) { 119 [3]=> 120 array(3) { 121 [0]=> 122 int(33) 123 [1]=> 124 int(-5) 125 [2]=> 126 int(6) 127 } 128 [2]=> 129 array(2) { 130 [0]=> 131 int(22) 132 [1]=> 133 int(-55) 134 } 135 [1]=> 136 array(1) { 137 [0]=> 138 int(11) 139 } 140 [0]=> 141 array(0) { 142 } 143} 144- Sort flag = SORT_REGULAR - 145bool(true) 146array(4) { 147 [3]=> 148 array(3) { 149 [0]=> 150 int(33) 151 [1]=> 152 int(-5) 153 [2]=> 154 int(6) 155 } 156 [2]=> 157 array(2) { 158 [0]=> 159 int(22) 160 [1]=> 161 int(-55) 162 } 163 [1]=> 164 array(1) { 165 [0]=> 166 int(11) 167 } 168 [0]=> 169 array(0) { 170 } 171} 172Done 173