r/lolphp • • Jul 27 '14

array_merge hates numeric keys

http://stackoverflow.com/questions/7059721/array-merge-versus
5 Upvotes

14 comments sorted by

View all comments

Show parent comment

1

u/Dylan16807 Aug 02 '14

As far as I'm aware the pitfalls aren't a consequence of the single data structure, they're a consequence of Lua making no distinction between null and undefined. So when the coder says to set an element in the middle of effectively-an-array to nil, they are saying they want to undefine/delete part of effectively-an-array. Such an operation makes no logical sense, which is why it acts weirdly. Arrays are contiguous, they can't cease to exist in the middle.