1--TEST-- 2Test array_reverse() function : usage variations - two dimensional arrays for 'array' argument 3--FILE-- 4<?php 5/* Prototype : array array_reverse(array $array [, bool $preserve_keys]) 6 * Description: Return input as a new array with the order of the entries reversed 7 * Source code: ext/standard/array.c 8*/ 9 10/* 11 * testing the functionality of array_reverse() by giving 2-D arrays for $array argument 12*/ 13 14echo "*** Testing array_reverse() : usage variations ***\n"; 15 16// Initializing the 2-d arrays 17$two_dimensional_array = array( 18 19 // associative array 20 array('color' => 'red', 'item' => 'pen', 'place' => 'LA'), 21 22 // numeric array 23 array(1, 2, 3, 4, 5), 24 25 // combination of numeric and associative arrays 26 array('a' => 'green', 'red', 'brown', 33, 88, 'orange', 'item' => 'ball') 27); 28 29// calling array_reverse() with various types of 2-d arrays 30// with default arguments 31echo "-- with default argument --\n"; 32var_dump( array_reverse($two_dimensional_array) ); // whole array 33var_dump( array_reverse($two_dimensional_array[1]) ); // sub array 34 35// with $preserve_keys argument 36echo "-- with all possible arguments --\n"; 37// whole array 38var_dump( array_reverse($two_dimensional_array, true) ); 39var_dump( array_reverse($two_dimensional_array, false) ); 40// sub array 41var_dump( array_reverse($two_dimensional_array[1], true) ); 42var_dump( array_reverse($two_dimensional_array[1], false) ); 43 44echo "Done"; 45?> 46--EXPECTF-- 47*** Testing array_reverse() : usage variations *** 48-- with default argument -- 49array(3) { 50 [0]=> 51 array(7) { 52 ["a"]=> 53 string(5) "green" 54 [0]=> 55 string(3) "red" 56 [1]=> 57 string(5) "brown" 58 [2]=> 59 int(33) 60 [3]=> 61 int(88) 62 [4]=> 63 string(6) "orange" 64 ["item"]=> 65 string(4) "ball" 66 } 67 [1]=> 68 array(5) { 69 [0]=> 70 int(1) 71 [1]=> 72 int(2) 73 [2]=> 74 int(3) 75 [3]=> 76 int(4) 77 [4]=> 78 int(5) 79 } 80 [2]=> 81 array(3) { 82 ["color"]=> 83 string(3) "red" 84 ["item"]=> 85 string(3) "pen" 86 ["place"]=> 87 string(2) "LA" 88 } 89} 90array(5) { 91 [0]=> 92 int(5) 93 [1]=> 94 int(4) 95 [2]=> 96 int(3) 97 [3]=> 98 int(2) 99 [4]=> 100 int(1) 101} 102-- with all possible arguments -- 103array(3) { 104 [2]=> 105 array(7) { 106 ["a"]=> 107 string(5) "green" 108 [0]=> 109 string(3) "red" 110 [1]=> 111 string(5) "brown" 112 [2]=> 113 int(33) 114 [3]=> 115 int(88) 116 [4]=> 117 string(6) "orange" 118 ["item"]=> 119 string(4) "ball" 120 } 121 [1]=> 122 array(5) { 123 [0]=> 124 int(1) 125 [1]=> 126 int(2) 127 [2]=> 128 int(3) 129 [3]=> 130 int(4) 131 [4]=> 132 int(5) 133 } 134 [0]=> 135 array(3) { 136 ["color"]=> 137 string(3) "red" 138 ["item"]=> 139 string(3) "pen" 140 ["place"]=> 141 string(2) "LA" 142 } 143} 144array(3) { 145 [0]=> 146 array(7) { 147 ["a"]=> 148 string(5) "green" 149 [0]=> 150 string(3) "red" 151 [1]=> 152 string(5) "brown" 153 [2]=> 154 int(33) 155 [3]=> 156 int(88) 157 [4]=> 158 string(6) "orange" 159 ["item"]=> 160 string(4) "ball" 161 } 162 [1]=> 163 array(5) { 164 [0]=> 165 int(1) 166 [1]=> 167 int(2) 168 [2]=> 169 int(3) 170 [3]=> 171 int(4) 172 [4]=> 173 int(5) 174 } 175 [2]=> 176 array(3) { 177 ["color"]=> 178 string(3) "red" 179 ["item"]=> 180 string(3) "pen" 181 ["place"]=> 182 string(2) "LA" 183 } 184} 185array(5) { 186 [4]=> 187 int(5) 188 [3]=> 189 int(4) 190 [2]=> 191 int(3) 192 [1]=> 193 int(2) 194 [0]=> 195 int(1) 196} 197array(5) { 198 [0]=> 199 int(5) 200 [1]=> 201 int(4) 202 [2]=> 203 int(3) 204 [3]=> 205 int(2) 206 [4]=> 207 int(1) 208} 209Done 210