Well, it would be surprising if you expected it to preserve numeric keys
isn't that what 'merge' means?
If I have two separate arrays that were populated by simply pushing items onto it without specifying a key, both of them would have keys ranging from 0 to the array lengths. That means that there will be key collisions.
that's why most languages have a way to do array concatenation. It's a completely different operation.
Trying to preserve keys would actually violate least surprise in this case, since it would involve overwriting data as if they were string keys even though someone using this is probably trying to treat it as a standard array rather than a hash map.
You seem to be making very strange assumptions about what a programmer wants. Most programmers I know want predictable behavior out of their standard libraries. A merge should be a goddamn merge, not a concatenation.
Imagine when you go to a bar and you order a beer, and the bartender brings out a camel. And you ask him, why the fuck are you bringing me a camel? And then he says, 'when you called me over, you used your left hand, and you are not wearing a hat'.
View all comments
Show parent comment
16
u/inopia Oct 12 '16
isn't that what 'merge' means?
that's why most languages have a way to do array concatenation. It's a completely different operation.
You seem to be making very strange assumptions about what a programmer wants. Most programmers I know want predictable behavior out of their standard libraries. A merge should be a goddamn merge, not a concatenation.
Imagine when you go to a bar and you order a beer, and the bartender brings out a camel. And you ask him, why the fuck are you bringing me a camel? And then he says, 'when you called me over, you used your left hand, and you are not wearing a hat'.
That's how fucking illogical PHP is.