3v4l.org

run code in 300+ PHP versions simultaneously
<?php function direct_product(array ...$arrays) { $result = [[]]; foreach ($result as $i => $x) { foreach ($arrays as $y) { $result[$i] = 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 ( ) */
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => array ( 0 => array ( 0 => 1, 1 => 2, ), ), )array ( 0 => array ( 0 => array ( 0 => 1, 1 => 2, ), ), )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
56.51 ms | 401 KiB | 8 Q