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 31--EXPECTF-- 32*** Testing array_slice() : usage variations *** 33 34-- $offset is -7 -- 35array(5) { 36 ["one"]=> 37 int(1) 38 [0]=> 39 string(3) "two" 40 [1]=> 41 string(5) "three" 42 [2]=> 43 string(4) "nine" 44 ["ten"]=> 45 int(10) 46} 47 48-- $offset is -6 -- 49array(5) { 50 ["one"]=> 51 int(1) 52 [0]=> 53 string(3) "two" 54 [1]=> 55 string(5) "three" 56 [2]=> 57 string(4) "nine" 58 ["ten"]=> 59 int(10) 60} 61 62-- $offset is -5 -- 63array(5) { 64 ["one"]=> 65 int(1) 66 [0]=> 67 string(3) "two" 68 [1]=> 69 string(5) "three" 70 [2]=> 71 string(4) "nine" 72 ["ten"]=> 73 int(10) 74} 75 76-- $offset is -4 -- 77array(4) { 78 [0]=> 79 string(3) "two" 80 [1]=> 81 string(5) "three" 82 [2]=> 83 string(4) "nine" 84 ["ten"]=> 85 int(10) 86} 87 88-- $offset is -3 -- 89array(3) { 90 [0]=> 91 string(5) "three" 92 [1]=> 93 string(4) "nine" 94 ["ten"]=> 95 int(10) 96} 97 98-- $offset is -2 -- 99array(2) { 100 [0]=> 101 string(4) "nine" 102 ["ten"]=> 103 int(10) 104} 105 106-- $offset is -1 -- 107array(1) { 108 ["ten"]=> 109 int(10) 110} 111 112-- $offset is 0 -- 113array(5) { 114 ["one"]=> 115 int(1) 116 [0]=> 117 string(3) "two" 118 [1]=> 119 string(5) "three" 120 [2]=> 121 string(4) "nine" 122 ["ten"]=> 123 int(10) 124} 125 126-- $offset is 1 -- 127array(4) { 128 [0]=> 129 string(3) "two" 130 [1]=> 131 string(5) "three" 132 [2]=> 133 string(4) "nine" 134 ["ten"]=> 135 int(10) 136} 137 138-- $offset is 2 -- 139array(3) { 140 [0]=> 141 string(5) "three" 142 [1]=> 143 string(4) "nine" 144 ["ten"]=> 145 int(10) 146} 147 148-- $offset is 3 -- 149array(2) { 150 [0]=> 151 string(4) "nine" 152 ["ten"]=> 153 int(10) 154} 155 156-- $offset is 4 -- 157array(1) { 158 ["ten"]=> 159 int(10) 160} 161 162-- $offset is 5 -- 163array(0) { 164} 165 166-- $offset is 6 -- 167array(0) { 168} 169 170-- $offset is 7 -- 171array(0) { 172} 173 174-- $offset is maximum integer value -- 175array(0) { 176} 177 178-- $offset is minimum integer value -- 179array(5) { 180 ["one"]=> 181 int(1) 182 [0]=> 183 string(3) "two" 184 [1]=> 185 string(5) "three" 186 [2]=> 187 string(4) "nine" 188 ["ten"]=> 189 int(10) 190} 191Done