1--TEST--
2yield from on multiple trees needing merge
3--FILE--
4<?php
5
6function from($levels) {
7	foreach (range(0, 2 << $levels) as $v) {
8		yield $v;
9	}
10}
11
12function gen($gen, $level) {
13	if ($level % 2) {
14		yield $gen->current();
15	}
16	yield from $gen;
17}
18
19foreach (range(0, 6) as $levels) {
20	print "$levels level".($levels == 1 ? "" : "s")."\n\n";
21
22	$all = array();
23	$all[] = $gens[0][0] = from($levels);
24
25	for ($level = 1; $level < $levels; $level++) {
26		for ($i = 0; $i < (1 << $level); $i++) {
27			$all[] = $gens[$level][$i] = gen($gens[$level-1][$i >> 1], $level);
28		}
29	}
30
31	while (1) {
32		foreach ($all as $gen) {
33			var_dump($gen->current());
34			$gen->next();
35			if (!$gen->valid()) {
36				break 2;
37			}
38		}
39	}
40
41	print "\n\n";
42}
43?>
44--EXPECT--
450 levels
46
47int(0)
48int(1)
49int(2)
50
51
521 level
53
54int(0)
55int(1)
56int(2)
57int(3)
58int(4)
59
60
612 levels
62
63int(0)
64int(1)
65int(2)
66int(3)
67int(4)
68int(5)
69int(6)
70int(7)
71int(8)
72
73
743 levels
75
76int(0)
77int(1)
78int(2)
79int(3)
80int(4)
81int(5)
82int(6)
83int(7)
84int(8)
85int(9)
86int(10)
87int(11)
88int(12)
89int(13)
90int(14)
91int(15)
92int(16)
93
94
954 levels
96
97int(0)
98int(1)
99int(2)
100int(3)
101int(4)
102int(5)
103int(6)
104int(7)
105int(8)
106int(9)
107int(10)
108int(11)
109int(12)
110int(13)
111int(14)
112int(15)
113int(16)
114int(17)
115int(18)
116int(19)
117int(20)
118int(21)
119int(22)
120int(23)
121int(24)
122int(25)
123int(26)
124int(27)
125int(28)
126int(29)
127int(30)
128int(31)
129int(32)
130
131
1325 levels
133
134int(0)
135int(1)
136int(2)
137int(3)
138int(4)
139int(5)
140int(6)
141int(7)
142int(8)
143int(9)
144int(10)
145int(11)
146int(12)
147int(13)
148int(14)
149int(15)
150int(16)
151int(17)
152int(18)
153int(19)
154int(20)
155int(21)
156int(22)
157int(23)
158int(24)
159int(25)
160int(26)
161int(27)
162int(28)
163int(29)
164int(30)
165int(31)
166int(32)
167int(33)
168int(34)
169int(35)
170int(36)
171int(37)
172int(38)
173int(39)
174int(40)
175int(41)
176int(42)
177int(43)
178int(44)
179int(45)
180int(46)
181int(47)
182int(48)
183int(49)
184int(50)
185int(51)
186int(52)
187int(53)
188int(54)
189int(55)
190int(56)
191int(57)
192int(58)
193int(59)
194int(60)
195int(61)
196int(62)
197int(63)
198int(64)
199
200
2016 levels
202
203int(0)
204int(1)
205int(2)
206int(3)
207int(4)
208int(5)
209int(6)
210int(7)
211int(8)
212int(9)
213int(10)
214int(11)
215int(12)
216int(13)
217int(14)
218int(15)
219int(16)
220int(17)
221int(18)
222int(19)
223int(20)
224int(21)
225int(22)
226int(23)
227int(24)
228int(25)
229int(26)
230int(27)
231int(28)
232int(29)
233int(30)
234int(31)
235int(32)
236int(33)
237int(34)
238int(35)
239int(36)
240int(37)
241int(38)
242int(39)
243int(40)
244int(41)
245int(42)
246int(43)
247int(44)
248int(45)
249int(46)
250int(47)
251int(48)
252int(49)
253int(50)
254int(51)
255int(52)
256int(53)
257int(54)
258int(55)
259int(56)
260int(57)
261int(58)
262int(59)
263int(60)
264int(61)
265int(62)
266int(63)
267int(64)
268int(65)
269int(66)
270int(67)
271int(68)
272int(69)
273int(70)
274int(71)
275int(72)
276int(73)
277int(74)
278int(75)
279int(76)
280int(77)
281int(78)
282int(79)
283int(80)
284int(81)
285int(82)
286int(83)
287int(84)
288int(85)
289int(86)
290int(87)
291int(88)
292int(89)
293int(90)
294int(91)
295int(92)
296int(93)
297int(94)
298int(95)
299int(96)
300int(97)
301int(98)
302int(99)
303int(100)
304int(101)
305int(102)
306int(103)
307int(104)
308int(105)
309int(106)
310int(107)
311int(108)
312int(109)
313int(110)
314int(111)
315int(112)
316int(113)
317int(114)
318int(115)
319int(116)
320int(117)
321int(118)
322int(119)
323int(120)
324int(121)
325int(122)
326int(123)
327int(124)
328int(125)
329int(126)
330int(127)
331int(128)
332