3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arrays = [ ['car' => '3', 'bus' => '2'], ['dog' => '1', 'car' => '2', 'bird' => '9'], ]; $defaults = array_fill(0, count($arrays), null); $result = []; foreach ($arrays as $i => $array) { foreach ($array as $k => $v){ $result[$k] ??= $defaults; $result[$k][$i] = $v; } } var_export($result);
Output for git.master, git.master_jit
array ( 'car' => array ( 0 => '3', 1 => '2', ), 'bus' => array ( 0 => '2', 1 => NULL, ), 'dog' => array ( 0 => NULL, 1 => '1', ), 'bird' => array ( 0 => NULL, 1 => '9', ), )

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:
62.82 ms | 405 KiB | 5 Q