1--TEST-- 2Test array_slice() function : usage variations - Pass different integers as $offset argument 3--FILE-- 4<?php 5/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) 6 * Description: Returns elements specified by offset and length 7 * Source code: ext/standard/array.c 8 */ 9 10/* 11 * Pass different integers as $offset argument to test how array_slice() behaves 12 */ 13 14echo "*** Testing array_slice() : usage variations ***\n"; 15 16$input = array ('one' => 1, 2 => 'two', 'three', 9 => 'nine', 'ten' => 10); 17 18for ($i = -7; $i <= 7; $i++) { 19 echo "\n-- \$offset is $i --\n"; 20 var_dump(array_slice($input, $i)); 21} 22echo "\n-- \$offset is maximum integer value --\n"; 23var_dump(array_slice($input, PHP_INT_MAX)); 24 25echo "\n-- \$offset is minimum integer value --\n"; 26var_dump(array_slice($input, -PHP_INT_MAX)); 27 28echo "Done"; 29?> 30--EXPECTF-- 31*** Testing array_slice() : usage variations *** 32 33-- $offset is -7 -- 34array(5) { 35 ["one"]=> 36 int(1) 37 [0]=> 38 string(3) "two" 39 [1]=> 40 string(5) "three" 41 [2]=> 42 string(4) "nine" 43 ["ten"]=> 44 int(10) 45} 46 47-- $offset is -6 -- 48array(5) { 49 ["one"]=> 50 int(1) 51 [0]=> 52 string(3) "two" 53 [1]=> 54 string(5) "three" 55 [2]=> 56 string(4) "nine" 57 ["ten"]=> 58 int(10) 59} 60 61-- $offset is -5 -- 62array(5) { 63 ["one"]=> 64 int(1) 65 [0]=> 66 string(3) "two" 67 [1]=> 68 string(5) "three" 69 [2]=> 70 string(4) "nine" 71 ["ten"]=> 72 int(10) 73} 74 75-- $offset is -4 -- 76array(4) { 77 [0]=> 78 string(3) "two" 79 [1]=> 80 string(5) "three" 81 [2]=> 82 string(4) "nine" 83 ["ten"]=> 84 int(10) 85} 86 87-- $offset is -3 -- 88array(3) { 89 [0]=> 90 string(5) "three" 91 [1]=> 92 string(4) "nine" 93 ["ten"]=> 94 int(10) 95} 96 97-- $offset is -2 -- 98array(2) { 99 [0]=> 100 string(4) "nine" 101 ["ten"]=> 102 int(10) 103} 104 105-- $offset is -1 -- 106array(1) { 107 ["ten"]=> 108 int(10) 109} 110 111-- $offset is 0 -- 112array(5) { 113 ["one"]=> 114 int(1) 115 [0]=> 116 string(3) "two" 117 [1]=> 118 string(5) "three" 119 [2]=> 120 string(4) "nine" 121 ["ten"]=> 122 int(10) 123} 124 125-- $offset is 1 -- 126array(4) { 127 [0]=> 128 string(3) "two" 129 [1]=> 130 string(5) "three" 131 [2]=> 132 string(4) "nine" 133 ["ten"]=> 134 int(10) 135} 136 137-- $offset is 2 -- 138array(3) { 139 [0]=> 140 string(5) "three" 141 [1]=> 142 string(4) "nine" 143 ["ten"]=> 144 int(10) 145} 146 147-- $offset is 3 -- 148array(2) { 149 [0]=> 150 string(4) "nine" 151 ["ten"]=> 152 int(10) 153} 154 155-- $offset is 4 -- 156array(1) { 157 ["ten"]=> 158 int(10) 159} 160 161-- $offset is 5 -- 162array(0) { 163} 164 165-- $offset is 6 -- 166array(0) { 167} 168 169-- $offset is 7 -- 170array(0) { 171} 172 173-- $offset is maximum integer value -- 174array(0) { 175} 176 177-- $offset is minimum integer value -- 178array(5) { 179 ["one"]=> 180 int(1) 181 [0]=> 182 string(3) "two" 183 [1]=> 184 string(5) "three" 185 [2]=> 186 string(4) "nine" 187 ["ten"]=> 188 int(10) 189} 190Done 191