- array_merge: documentation ( source)
- json_encode: documentation ( source)
<?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;