3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Everything you enter here will be executed by our servers. Try it! function iterator_compose() { foreach (array_reverse(func_get_args()) as $it) { if (is_callable($it)) { $prev = $it; } } } function iterator_chunk($it, $chunkSize) { $chunk = []; $i = 0; foreach ($it as $val) { $chunk[] = $val; $i++; if ($i === $chunkSize) { yield $chunk; $chunk = []; $i = 0; } } } foreach (iterator_chunk(range(0, 128), 32) as $i => $c) { echo "====== Chunk $i ======\n"; var_export($c); echo "\n"; }
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
====== Chunk 0 ====== array ( 0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 11 => 11, 12 => 12, 13 => 13, 14 => 14, 15 => 15, 16 => 16, 17 => 17, 18 => 18, 19 => 19, 20 => 20, 21 => 21, 22 => 22, 23 => 23, 24 => 24, 25 => 25, 26 => 26, 27 => 27, 28 => 28, 29 => 29, 30 => 30, 31 => 31, ) ====== Chunk 1 ====== array ( 0 => 32, 1 => 33, 2 => 34, 3 => 35, 4 => 36, 5 => 37, 6 => 38, 7 => 39, 8 => 40, 9 => 41, 10 => 42, 11 => 43, 12 => 44, 13 => 45, 14 => 46, 15 => 47, 16 => 48, 17 => 49, 18 => 50, 19 => 51, 20 => 52, 21 => 53, 22 => 54, 23 => 55, 24 => 56, 25 => 57, 26 => 58, 27 => 59, 28 => 60, 29 => 61, 30 => 62, 31 => 63, ) ====== Chunk 2 ====== array ( 0 => 64, 1 => 65, 2 => 66, 3 => 67, 4 => 68, 5 => 69, 6 => 70, 7 => 71, 8 => 72, 9 => 73, 10 => 74, 11 => 75, 12 => 76, 13 => 77, 14 => 78, 15 => 79, 16 => 80, 17 => 81, 18 => 82, 19 => 83, 20 => 84, 21 => 85, 22 => 86, 23 => 87, 24 => 88, 25 => 89, 26 => 90, 27 => 91, 28 => 92, 29 => 93, 30 => 94, 31 => 95, ) ====== Chunk 3 ====== array ( 0 => 96, 1 => 97, 2 => 98, 3 => 99, 4 => 100, 5 => 101, 6 => 102, 7 => 103, 8 => 104, 9 => 105, 10 => 106, 11 => 107, 12 => 108, 13 => 109, 14 => 110, 15 => 111, 16 => 112, 17 => 113, 18 => 114, 19 => 115, 20 => 116, 21 => 117, 22 => 118, 23 => 119, 24 => 120, 25 => 121, 26 => 122, 27 => 123, 28 => 124, 29 => 125, 30 => 126, 31 => 127, )
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '$chunk' (T_VARIABLE) in /in/k5hU1 on line 22
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/k5hU1 on line 15
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/k5hU1 on line 15
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/k5hU1 on line 15
Process exited with code 255.

preferences:
264.65 ms | 401 KiB | 398 Q