I have the following array below, doing an experiment on union operator.
$a = array(1,2,3,6);
$b = array(1, 2, 3, 4, 5);
$c = $b + $a;
$c seems to be 1,2,3,4,5
Thus I assume array $b is check against array $a. 6 doesn’t exist in $b, so it doesn’t add to it.
Now, if I were to switch it to
$c = $a + $b, I would expect (1,2,3,6) only.
However, the actual output is (1,2,3,6,5).
Can anyone explain this?
I think you misunderstood with how
+operator works witharray.When
+is used forarrayit basically merges 2 arrays bykeysnotvaluesFor example. I’ll explain why
$chas difference result than you expected.