3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // Simple merging table $arrayFirst = [10, 50, 20, 40, 30]; $arraySecond = [1.0, 5.0, 2.0, 4.0, 3.0]; print_r(array_merge($arrayFirst, $arraySecond)); // Sorted tables $tableFirst = [ '2011:london' => ['city' => 'London', 'year' => 2011, 'birthrate' => 'over9000'], '2012:birmingham' => ['city' => 'Birmingham', 'year' => 2012, 'birthrate' => 'wat'], '2013:london' => ['city' => 'London', 'year' => 2013, 'birthrate' => 'boo boo'] ]; $tableSecond = [ '2011:london' => ['city' => 'London', 'year' => 2011, 'comment' => 1], '2012:london' => ['city' => 'London', 'year' => 2012, 'comment' => 2], '2014:london' => ['city' => 'London', 'year' => 2014, 'comment' => 3] ]; var_dump($tableFirst, $tableSecond); // New func for merging sorted by unique key table-like arrays! function array_linear_merge($arrayLeft, $arrayRight) { $iteratorLeft = new ArrayIterator($arrayLeft); $iteratorRight = new ArrayIterator($arrayRight); }
based on DvDLi
Output for 5.4.0 - 5.4.32
Parse error: syntax error, unexpected ''birthrate'' (T_CONSTANT_ENCAPSED_STRING), expecting ']' in /in/NnCcd on line 10
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/NnCcd on line 4
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/NnCcd on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/NnCcd on line 4
Process exited with code 255.