[1=>0]+[2=>0] yields [1=>0,2=>0]. But is there any trick to use such syntax sugar for [1]+[2]. So [1]+[2] yeilds [1,2]?
note: My concern is about such syntax, not about other related PHP functions.
Use array_merge() instead. I stumped across so much of strange behavior of + used with arrays that I promised myself to never use it ever again.
+ is the array union operator, which will skip existing keys.
You want array_merge() which will concatenate them in your example (it does that for arrays with numeric keys).
Unfortunately for you, there is no way to overload the + operator to perform anything different.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With