3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function zip(...$arr){ $newArr = []; $count_max = 0; foreach($arr as $a) { $newArr[] = array_reverse($a); $count_max = count($a) > $count_max ? count($a) : $count_max; } while($count_max) { $return = []; foreach($newArr as &$a) $return[] = array_pop($a); yield $return; $count_max--; }; } $i = ['a', 'b', 'c', 'd']; $j = ['1', '2', '3', '4']; $g = ['!', '@', '#', '$']; $c = 0; foreach(zip($i, $j, $g) as [$k, $l, $m]) { $c++; printf("%s-%d-%s - Count: %d\n", $k, $l, $m, $c); }
based on cNLqh
Output for 7.1.0 - 7.2.6
a-1-! - Count: 1 b-2-@ - Count: 2 c-3-# - Count: 3 d-4-$ - Count: 4
Output for 7.0.0 - 7.0.20
Parse error: syntax error, unexpected ')', expecting :: (T_PAAMAYIM_NEKUDOTAYIM) in /in/9aqpl on line 28
Process exited with code 255.
Output for hhvm-3.15.4
Fatal error: Uncaught Error: syntax error, unexpected ')', expecting '(' in /in/9aqpl:28 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected '[' in /in/9aqpl on line 28
Process exited with code 255.