3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array1 = [ '1' => '11', 'b' => 1, 3 => 33, 8 => 8 ]; $array2 = [ '1' => '22', 'b' => 2, 3 => 44, 9 => 9 ]; foreach ($array2 as $key => $value) { if (!key_exists($key, $array1)) { $array1[$key] = $value; } else { $array1[$key] = (array)$array1[$key]; $array1[$key][] = $value; } } var_export($array1);
Output for git.master, git.master_jit, rfc.property-hooks
array ( 1 => array ( 0 => '11', 1 => '22', ), 'b' => array ( 0 => 1, 1 => 2, ), 3 => array ( 0 => 33, 1 => 44, ), 8 => 8, 9 => 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:
189.4 ms | 405 KiB | 5 Q