1--TEST--
2Test array_slice() function : usage variations - pass different int values as $length arg
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 integer values as $length argument to array_slice() to test behaviour
12 */
13
14echo "*** Testing array_slice() : usage variations ***\n";
15
16$input = array ('one' => 1, 2 => 'two', 'three', 9 => 'nine', 'ten' => 10);
17$offset = 1;
18
19for ($i = -6; $i <= 6; $i++) {
20	echo "\n-- \$length is $i --\n";
21	var_dump(array_slice($input, $offset, $i));
22}
23echo "\n-- \$length is maximum integer value --\n";
24var_dump(array_slice($input, $offset, PHP_INT_MAX));
25
26echo "\n-- \$length is minimum integer value --\n";
27var_dump(array_slice($input, $offset, -PHP_INT_MAX));
28
29echo "Done";
30?>
31
32--EXPECTF--
33*** Testing array_slice() : usage variations ***
34
35-- $length is -6 --
36array(0) {
37}
38
39-- $length is -5 --
40array(0) {
41}
42
43-- $length is -4 --
44array(0) {
45}
46
47-- $length is -3 --
48array(1) {
49  [0]=>
50  string(3) "two"
51}
52
53-- $length is -2 --
54array(2) {
55  [0]=>
56  string(3) "two"
57  [1]=>
58  string(5) "three"
59}
60
61-- $length is -1 --
62array(3) {
63  [0]=>
64  string(3) "two"
65  [1]=>
66  string(5) "three"
67  [2]=>
68  string(4) "nine"
69}
70
71-- $length is 0 --
72array(0) {
73}
74
75-- $length is 1 --
76array(1) {
77  [0]=>
78  string(3) "two"
79}
80
81-- $length is 2 --
82array(2) {
83  [0]=>
84  string(3) "two"
85  [1]=>
86  string(5) "three"
87}
88
89-- $length is 3 --
90array(3) {
91  [0]=>
92  string(3) "two"
93  [1]=>
94  string(5) "three"
95  [2]=>
96  string(4) "nine"
97}
98
99-- $length is 4 --
100array(4) {
101  [0]=>
102  string(3) "two"
103  [1]=>
104  string(5) "three"
105  [2]=>
106  string(4) "nine"
107  ["ten"]=>
108  int(10)
109}
110
111-- $length is 5 --
112array(4) {
113  [0]=>
114  string(3) "two"
115  [1]=>
116  string(5) "three"
117  [2]=>
118  string(4) "nine"
119  ["ten"]=>
120  int(10)
121}
122
123-- $length is 6 --
124array(4) {
125  [0]=>
126  string(3) "two"
127  [1]=>
128  string(5) "three"
129  [2]=>
130  string(4) "nine"
131  ["ten"]=>
132  int(10)
133}
134
135-- $length is maximum integer value --
136array(4) {
137  [0]=>
138  string(3) "two"
139  [1]=>
140  string(5) "three"
141  [2]=>
142  string(4) "nine"
143  ["ten"]=>
144  int(10)
145}
146
147-- $length is minimum integer value --
148array(0) {
149}
150Done
151