1--TEST--
2Test array_slice() function : usage variations - array has holes in buckets
3--FILE--
4<?php
5/*
6 * Check that results of array_slice are correct when there are holes in buckets caused by unset()
7 */
8
9echo "*** Testing array_slice() : usage variations ***\n";
10
11function dump_slice(array $input, $offsetToUnset, int $offset, int $length) {
12    unset($input[$offsetToUnset]);
13    var_dump(array_slice($input, $offset, $length));
14}
15
16echo "\n-- Call array_slice() on array with string keys--\n";
17$input = ['one' => 'un', 'two' => 'deux', 23 => 'twenty-three', 'zero'];
18dump_slice($input, 'two', 0, 1);
19dump_slice($input, 'two', 0, 2);
20dump_slice($input, 'two', 0, 3);
21dump_slice($input, 23, 1, 2);
22
23echo "\n-- Call array_slice() on array with packed keys--\n";
24$input = [10, 11, 12, 'thirteen'];
25dump_slice($input, 0, 0, 1);
26dump_slice($input, 1, 0, 1);
27dump_slice($input, 1, 0, 3);
28dump_slice($input, 1, -1, 1);
29dump_slice($input, 1, 0, 3);
30dump_slice($input, 1, -3, 3);
31
32echo "Done";
33?>
34--EXPECT--
35*** Testing array_slice() : usage variations ***
36
37-- Call array_slice() on array with string keys--
38array(1) {
39  ["one"]=>
40  string(2) "un"
41}
42array(2) {
43  ["one"]=>
44  string(2) "un"
45  [0]=>
46  string(12) "twenty-three"
47}
48array(3) {
49  ["one"]=>
50  string(2) "un"
51  [0]=>
52  string(12) "twenty-three"
53  [1]=>
54  string(4) "zero"
55}
56array(2) {
57  ["two"]=>
58  string(4) "deux"
59  [0]=>
60  string(4) "zero"
61}
62
63-- Call array_slice() on array with packed keys--
64array(1) {
65  [0]=>
66  int(11)
67}
68array(1) {
69  [0]=>
70  int(10)
71}
72array(3) {
73  [0]=>
74  int(10)
75  [1]=>
76  int(12)
77  [2]=>
78  string(8) "thirteen"
79}
80array(1) {
81  [0]=>
82  string(8) "thirteen"
83}
84array(3) {
85  [0]=>
86  int(10)
87  [1]=>
88  int(12)
89  [2]=>
90  string(8) "thirteen"
91}
92array(3) {
93  [0]=>
94  int(10)
95  [1]=>
96  int(12)
97  [2]=>
98  string(8) "thirteen"
99}
100Done
101