3v4l.org

run code in 300+ PHP versions simultaneously
<?php $trucks = ['Serial' => 12345, 'Wheels' => 4, 'Color' => 'Black']; $trailers = ['Serial' =>4321, 'Length'=>42]; $forklifts = ['Serial' =>5678, 'ForkLength'=>24]; $columns = array_keys(array_merge($trucks, $trailers, $forklifts)); $template = array_fill_keys($columns, null); foreach ([$trucks, $trailers, $forklifts] as $array) { $result[] = array_merge($template, $array); } var_dump($result);
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
array(3) { [0]=> array(5) { ["Serial"]=> int(12345) ["Wheels"]=> int(4) ["Color"]=> string(5) "Black" ["Length"]=> NULL ["ForkLength"]=> NULL } [1]=> array(5) { ["Serial"]=> int(4321) ["Wheels"]=> NULL ["Color"]=> NULL ["Length"]=> int(42) ["ForkLength"]=> NULL } [2]=> array(5) { ["Serial"]=> int(5678) ["Wheels"]=> NULL ["Color"]=> NULL ["Length"]=> NULL ["ForkLength"]=> int(24) } }

preferences:
110.42 ms | 409 KiB | 5 Q