3v4l.org

run code in 500+ PHP versions simultaneously
<?php $iterator = new ArrayIterator(range(1, 100)); function iterable_chunk(iterable $array, int $chunkSize) { for($i=0;;$i++) { $g = (function() use ($array, $chunkSize, $i) { $c = -1; $y = 0; foreach($array as $item) { $c ++; if ($c < $i*$chunkSize) { continue; } if ($c > ($i+1)*$chunkSize-1) { break; } $y ++; yield $item; } if ($y != $chunkSize) { throw new \Exception(); } })(); yield $g; } } try { foreach(iterable_chunk($iterator, 10) as $it1) { foreach ($it1 as $it) { echo $it . " "; } echo "\n"; } } catch (\Exception $e) {}
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.32, 8.3.0 - 8.3.4, 8.3.6 - 8.3.32, 8.4.1 - 8.4.24, 8.5.0 - 8.5.9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
Output for 7.0.0 - 7.0.33
Fatal error: Uncaught TypeError: Argument 1 passed to iterable_chunk() must be an instance of iterable, instance of ArrayIterator given, called in /in/clLL9 on line 34 and defined in /in/clLL9:5 Stack trace: #0 /in/clLL9(34): iterable_chunk(Object(ArrayIterator), 10) #1 {main} thrown in /in/clLL9 on line 5
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Parse error: syntax error, unexpected '(' in /in/clLL9 on line 26
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '$item' (T_VARIABLE) in /in/clLL9 on line 21
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected T_VARIABLE in /in/clLL9 on line 21
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/clLL9 on line 9
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/clLL9 on line 9
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/clLL9 on line 5
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
Parse error: parse error, unexpected T_STRING, expecting ')' in /in/clLL9 on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/clLL9 on line 5
Process exited with code 255.

preferences:
139.34 ms | 2826 KiB | 4 Q