1--TEST-- 2Test array_slice() function : usage variations - Pass different data types as $length arg 3--SKIPIF-- 4<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> 5--FILE-- 6<?php 7/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) 8 * Description: Returns elements specified by offset and length 9 * Source code: ext/standard/array.c 10 */ 11 12/* 13 * Pass different data types as $length argument to array_slice to test behaviour 14 */ 15 16echo "*** Testing array_slice() : usage variations ***\n"; 17 18// Initialise function arguments not being substituted 19$input_array = array('one' => 1, 2, 'three' => 3, 4); 20$offset = 2; 21 22//get an unset variable 23$unset_var = 10; 24unset ($unset_var); 25 26// heredoc string 27$heredoc = <<<EOT 28hello world 29EOT; 30 31// unexpected values to be passed to $length argument 32$inputs = array( 33 34 // int data 35/*1*/ 0, 36 1, 37 12345, 38 -2345, 39 40 // float data 41/*5*/ 10.5, 42 -10.5, 43 12.3456789000e10, 44 12.3456789000E-10, 45 .5, 46 47 // null data 48/*10*/ NULL, 49 null, 50 51 // boolean data 52/*12*/ true, 53 false, 54 TRUE, 55 FALSE, 56 57 // empty data 58/*16*/ "", 59 '', 60 array(), 61 62 // string data 63/*19*/ "string", 64 'string', 65 $heredoc, 66 67 // undefined data 68/*22*/ @$undefined_var, 69 70 // unset data 71/*23*/ @$unset_var, 72); 73 74// loop through each element of $inputs to check the behavior of array_slice 75$iterator = 1; 76foreach($inputs as $input) { 77 echo "\n-- Iteration $iterator --\n"; 78 var_dump( array_slice($input_array, $offset, $input) ); 79 $iterator++; 80}; 81 82echo "Done"; 83?> 84--EXPECT-- 85*** Testing array_slice() : usage variations *** 86 87-- Iteration 1 -- 88array(0) { 89} 90 91-- Iteration 2 -- 92array(1) { 93 ["three"]=> 94 int(3) 95} 96 97-- Iteration 3 -- 98array(2) { 99 ["three"]=> 100 int(3) 101 [0]=> 102 int(4) 103} 104 105-- Iteration 4 -- 106array(0) { 107} 108 109-- Iteration 5 -- 110array(2) { 111 ["three"]=> 112 int(3) 113 [0]=> 114 int(4) 115} 116 117-- Iteration 6 -- 118array(0) { 119} 120 121-- Iteration 7 -- 122array(2) { 123 ["three"]=> 124 int(3) 125 [0]=> 126 int(4) 127} 128 129-- Iteration 8 -- 130array(0) { 131} 132 133-- Iteration 9 -- 134array(0) { 135} 136 137-- Iteration 10 -- 138array(2) { 139 ["three"]=> 140 int(3) 141 [0]=> 142 int(4) 143} 144 145-- Iteration 11 -- 146array(2) { 147 ["three"]=> 148 int(3) 149 [0]=> 150 int(4) 151} 152 153-- Iteration 12 -- 154array(1) { 155 ["three"]=> 156 int(3) 157} 158 159-- Iteration 13 -- 160array(0) { 161} 162 163-- Iteration 14 -- 164array(1) { 165 ["three"]=> 166 int(3) 167} 168 169-- Iteration 15 -- 170array(0) { 171} 172 173-- Iteration 16 -- 174array(0) { 175} 176 177-- Iteration 17 -- 178array(0) { 179} 180 181-- Iteration 18 -- 182array(0) { 183} 184 185-- Iteration 19 -- 186array(0) { 187} 188 189-- Iteration 20 -- 190array(0) { 191} 192 193-- Iteration 21 -- 194array(0) { 195} 196 197-- Iteration 22 -- 198array(2) { 199 ["three"]=> 200 int(3) 201 [0]=> 202 int(4) 203} 204 205-- Iteration 23 -- 206array(2) { 207 ["three"]=> 208 int(3) 209 [0]=> 210 int(4) 211} 212Done 213