1--TEST--
2Test array_splice(): basic functionality
3--FILE--
4<?php
5/*
6 * Function is implemented in ext/standard/array.c
7*/
8
9echo "*** Testing array_splice() basic operations ***\n";
10echo "test truncation \n";
11$input = array("red", "green", "blue", "yellow");
12var_dump (array_splice($input, 2));
13var_dump ($input);
14// $input is now array("red", "green")
15
16echo "test truncation with null length \n";
17$input = array("red", "green", "blue", "yellow");
18var_dump (array_splice($input, 2, null));
19var_dump ($input);
20// $input is now array("red", "green")
21
22echo "test removing entries from the middle \n";
23$input = array("red", "green", "blue", "yellow");
24var_dump (array_splice($input, 1, -1));
25var_dump ($input);
26// $input is now array("red", "yellow")
27
28echo "test substitution at end \n";
29$input = array("red", "green", "blue", "yellow");
30var_dump (array_splice($input, 1, count($input), "orange"));
31var_dump ($input);
32// $input is now array("red", "orange")
33
34$input = array("red", "green", "blue", "yellow");
35var_dump (array_splice($input, -1, 1, array("black", "maroon")));
36var_dump ($input);
37// $input is now array("red", "green",
38//          "blue", "black", "maroon")
39
40echo "test insertion \n";
41$input = array("red", "green", "blue", "yellow");
42var_dump (array_splice($input, 3, 0, "purple"));
43var_dump ($input);
44// $input is now array("red", "green",
45//          "blue", "purple", "yellow");
46
47
48?>
49--EXPECT--
50*** Testing array_splice() basic operations ***
51test truncation
52array(2) {
53  [0]=>
54  string(4) "blue"
55  [1]=>
56  string(6) "yellow"
57}
58array(2) {
59  [0]=>
60  string(3) "red"
61  [1]=>
62  string(5) "green"
63}
64test truncation with null length
65array(2) {
66  [0]=>
67  string(4) "blue"
68  [1]=>
69  string(6) "yellow"
70}
71array(2) {
72  [0]=>
73  string(3) "red"
74  [1]=>
75  string(5) "green"
76}
77test removing entries from the middle
78array(2) {
79  [0]=>
80  string(5) "green"
81  [1]=>
82  string(4) "blue"
83}
84array(2) {
85  [0]=>
86  string(3) "red"
87  [1]=>
88  string(6) "yellow"
89}
90test substitution at end
91array(3) {
92  [0]=>
93  string(5) "green"
94  [1]=>
95  string(4) "blue"
96  [2]=>
97  string(6) "yellow"
98}
99array(2) {
100  [0]=>
101  string(3) "red"
102  [1]=>
103  string(6) "orange"
104}
105array(1) {
106  [0]=>
107  string(6) "yellow"
108}
109array(5) {
110  [0]=>
111  string(3) "red"
112  [1]=>
113  string(5) "green"
114  [2]=>
115  string(4) "blue"
116  [3]=>
117  string(5) "black"
118  [4]=>
119  string(6) "maroon"
120}
121test insertion
122array(0) {
123}
124array(5) {
125  [0]=>
126  string(3) "red"
127  [1]=>
128  string(5) "green"
129  [2]=>
130  string(4) "blue"
131  [3]=>
132  string(6) "purple"
133  [4]=>
134  string(6) "yellow"
135}
136