In PHP, (given that $a, $b and $c are arrays) is $a = array_replace($b, $c) always functionally identical to $a = $c + $b?
I can’t seem to find any edge cases that would indicate otherwise.
(just working with one dimension, this question isn’t concerned with recursion, ie: array_replace_recursive())
Edit: I found a note in a comment that suggests that the union operator will preserve references, but I haven’t noticed array_replace() failing to do that.
EDIT: Ah sorry, I didn’t notice the arguments were reversed. The answer is yes, then, because the resulting array always has the two arrays merged, but while
+gives priority to values in the first array andarray_replaceto the second.The only actual difference would be in terms of performance, where
+may be preferable because when it finds duplicates it doesn’t replace the value; it just moves on. Plus, it doesn’t entail a (relatively expensive) function call.No.
array_replacereplaces elements, while+considers the first value:Array ( [0] => 2 ) Array ( [0] => 1 )To cite the manual:
As for references, they are preserved in both cases.