3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $array = [ 8 => [ 'Blue', 'Red', 'Pink' ], 2 => [ 'S', 'M' ] ]; $combinations = [[]]; $comKeys = array_keys($data); for ($count = 0; $count < count($comKeys); $count++) { $tmp = []; foreach ($combinations as $v1) { foreach ($data[$comKeys[$count]] as $v2) $tmp[] = $v1 + [$comKeys[$count] => $v2]; } $combinations = $tmp; } print_r($combinations);
Output for 7.2.0
Notice: Undefined variable: data in /in/nMJWN on line 16 Warning: array_keys() expects parameter 1 to be array, null given in /in/nMJWN on line 16 Warning: count(): Parameter must be an array or an object that implements Countable in /in/nMJWN on line 19 Array ( [0] => Array ( ) )
Output for 5.4.11 - 7.1.10
Notice: Undefined variable: data in /in/nMJWN on line 16 Warning: array_keys() expects parameter 1 to be array, null given in /in/nMJWN on line 16 Array ( [0] => Array ( ) )
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/nMJWN on line 3
Process exited with code 255.