xref: /PHP-8.0/Zend/tests/array_unpack/basic.phpt (revision 7aacc705)
1--TEST--
2Basic array unpacking
3--FILE--
4<?php
5$array = [1, 2, 3];
6
7function getArr() {
8    return [4, 5];
9}
10
11function arrGen() {
12    for($i = 11; $i < 15; $i++) {
13        yield $i;
14    }
15}
16
17var_dump([...[]]);
18var_dump([...[1, 2, 3]]);
19var_dump([...$array]);
20var_dump([...getArr()]);
21var_dump([...arrGen()]);
22var_dump([...new ArrayIterator(['a', 'b', 'c'])]);
23
24var_dump([0, ...$array, ...getArr(), 6, 7, 8, 9, 10, ...arrGen()]);
25var_dump([0, ...$array, ...$array, 'end']);
26
27?>
28--EXPECT--
29array(0) {
30}
31array(3) {
32  [0]=>
33  int(1)
34  [1]=>
35  int(2)
36  [2]=>
37  int(3)
38}
39array(3) {
40  [0]=>
41  int(1)
42  [1]=>
43  int(2)
44  [2]=>
45  int(3)
46}
47array(2) {
48  [0]=>
49  int(4)
50  [1]=>
51  int(5)
52}
53array(4) {
54  [0]=>
55  int(11)
56  [1]=>
57  int(12)
58  [2]=>
59  int(13)
60  [3]=>
61  int(14)
62}
63array(3) {
64  [0]=>
65  string(1) "a"
66  [1]=>
67  string(1) "b"
68  [2]=>
69  string(1) "c"
70}
71array(15) {
72  [0]=>
73  int(0)
74  [1]=>
75  int(1)
76  [2]=>
77  int(2)
78  [3]=>
79  int(3)
80  [4]=>
81  int(4)
82  [5]=>
83  int(5)
84  [6]=>
85  int(6)
86  [7]=>
87  int(7)
88  [8]=>
89  int(8)
90  [9]=>
91  int(9)
92  [10]=>
93  int(10)
94  [11]=>
95  int(11)
96  [12]=>
97  int(12)
98  [13]=>
99  int(13)
100  [14]=>
101  int(14)
102}
103array(8) {
104  [0]=>
105  int(0)
106  [1]=>
107  int(1)
108  [2]=>
109  int(2)
110  [3]=>
111  int(3)
112  [4]=>
113  int(1)
114  [5]=>
115  int(2)
116  [6]=>
117  int(3)
118  [7]=>
119  string(3) "end"
120}
121