3v4l.org

run code in 300+ PHP versions simultaneously
<?php $source = ["a" => 1, "b" => 2, "c" => 3]; $input = ["d" => 4, "b" => 10]; echo "With + operator:\n"; echo "input + source | " . json_encode($input + $source) . PHP_EOL; echo "source + input | " . json_encode($source + $input) . PHP_EOL; echo "With array_merge:\n"; echo "input + source | " . json_encode(array_merge($input, $source)) . PHP_EOL; echo "source + input | " . json_encode(array_merge($source, $input)) . PHP_EOL;
Output for 7.3.0 - 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.25, 8.4.1 - 8.4.12
With + operator: input + source | {"d":4,"b":10,"a":1,"c":3} source + input | {"a":1,"b":2,"c":3,"d":4} With array_merge: input + source | {"d":4,"b":2,"a":1,"c":3} source + input | {"a":1,"b":10,"c":3,"d":4}

preferences:
130.31 ms | 407 KiB | 5 Q