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--EXPECT--
32*** Testing array_slice() : usage variations ***
33
34-- $length is -6 --
35array(0) {
36}
37
38-- $length is -5 --
39array(0) {
40}
41
42-- $length is -4 --
43array(0) {
44}
45
46-- $length is -3 --
47array(1) {
48  [0]=>
49  string(3) "two"
50}
51
52-- $length is -2 --
53array(2) {
54  [0]=>
55  string(3) "two"
56  [1]=>
57  string(5) "three"
58}
59
60-- $length is -1 --
61array(3) {
62  [0]=>
63  string(3) "two"
64  [1]=>
65  string(5) "three"
66  [2]=>
67  string(4) "nine"
68}
69
70-- $length is 0 --
71array(0) {
72}
73
74-- $length is 1 --
75array(1) {
76  [0]=>
77  string(3) "two"
78}
79
80-- $length is 2 --
81array(2) {
82  [0]=>
83  string(3) "two"
84  [1]=>
85  string(5) "three"
86}
87
88-- $length is 3 --
89array(3) {
90  [0]=>
91  string(3) "two"
92  [1]=>
93  string(5) "three"
94  [2]=>
95  string(4) "nine"
96}
97
98-- $length is 4 --
99array(4) {
100  [0]=>
101  string(3) "two"
102  [1]=>
103  string(5) "three"
104  [2]=>
105  string(4) "nine"
106  ["ten"]=>
107  int(10)
108}
109
110-- $length is 5 --
111array(4) {
112  [0]=>
113  string(3) "two"
114  [1]=>
115  string(5) "three"
116  [2]=>
117  string(4) "nine"
118  ["ten"]=>
119  int(10)
120}
121
122-- $length is 6 --
123array(4) {
124  [0]=>
125  string(3) "two"
126  [1]=>
127  string(5) "three"
128  [2]=>
129  string(4) "nine"
130  ["ten"]=>
131  int(10)
132}
133
134-- $length is maximum integer value --
135array(4) {
136  [0]=>
137  string(3) "two"
138  [1]=>
139  string(5) "three"
140  [2]=>
141  string(4) "nine"
142  ["ten"]=>
143  int(10)
144}
145
146-- $length is minimum integer value --
147array(0) {
148}
149Done
150