3v4l.org

run code in 200+ php & hhvm versions
<?php function multiArrayCombine() { $transposed = array_map(null, ...func_get_args()); foreach ($transposed as &$set) { $set = array_merge(...array_filter($set)); } return $transposed; } $array1 = [['a' => 'val1'], ['a' => 'val2']]; $array2 = [['b' => 'val3'], ['b' => 'val4']]; $array3 = [['c' => 'val5'], [], ['c' => 'val6']]; var_export(multiArrayCombine($array1, $array2, $array3));
based on 2COFK
Output for 5.6.0 - 5.6.40, hhvm-3.10.1 - 3.22.0, 7.0.0 - 7.4.0alpha1
array ( 0 => array ( 'a' => 'val1', 'b' => 'val3', 'c' => 'val5', ), 1 => array ( 'a' => 'val2', 'b' => 'val4', ), 2 => array ( 'c' => 'val6', ), )
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.5.38
Parse error: syntax error, unexpected '.' in /in/N8N8h on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '.' in /in/N8N8h on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/N8N8h on line 3
Process exited with code 255.