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