3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function direct_product(array ...$arrays) { $result = [[]]; foreach ($result as $i => $x) { foreach ($arrays as $j => $y) { $result[$i][$j] = array_merge($x, [$y]); } } return $result; } var_export(direct_product(['A', 'B', 'C'], ['a'], [1, 2])); /* array ( 0 => array ( 0 => 'A', 1 => 'a', 2 => 1, ), 1 => array ( 0 => 'A', 1 => 'a', 2 => 2, ), 2 => array ( 0 => 'B', 1 => 'a', 2 => 1, ), 3 => array ( 0 => 'B', 1 => 'a', 2 => 2, ), 4 => array ( 0 => 'C', 1 => 'a', 2 => 1, ), 5 => array ( 0 => 'C', 1 => 'a', 2 => 2, ), ) */ var_export(direct_product(['A', 'B', 'C'], [], [1, 2])); /* array ( ) */
based on EkJ2Y
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.3.0alpha1
array ( 0 => array ( 0 => array ( 0 => array ( 0 => 'A', 1 => 'B', 2 => 'C', ), ), 1 => array ( 0 => array ( 0 => 'a', ), ), 2 => array ( 0 => array ( 0 => 1, 1 => 2, ), ), ), )array ( 0 => array ( 0 => array ( 0 => array ( 0 => 'A', 1 => 'B', 2 => 'C', ), ), 1 => array ( 0 => array ( ), ), 2 => array ( 0 => array ( 0 => 1, 1 => 2, ), ), ), )
Output for hhvm-3.15.4 - 3.17.3
Fatal error: Uncaught Error: Parameter $arrays is variadic and has a type constraint (array); variadic params with type constraints are not supported in non-Hack files in /in/OuJSU:3 Stack trace: #0 {main}
Process exited with code 255.
Output for hhvm-3.12.14
Fatal error: Uncaught Error: Parameter $arrays is variadic and has a type constraint (array); variadic params with type constraints are not supported in /in/OuJSU:3 Stack trace: #0 {main}
Process exited with code 255.