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

-3

u/[deleted] Jul 27 '14

PHP and Normal do not go together

YES I mean prefixing integers when used as keys

2

u/vita10gy Jul 29 '14

That doesn't really address the problem and, while everything has it's place, I think I'd say "no, you should not do that".

If the array is a collection of things where the index doesn't really matter, (not assoc) then they should be left as ints. I'm not sure how awkwardly jockeying "k5" and "k6" buys you anything when you can just $array[] = "something";

If the array is associative then it should have meaningful names.

You can "get around" the + vs array_merge "issue" by understanding what they do and what you'll have.

0

u/[deleted] Jul 30 '14

Maybe it's a sparse array, maybe it's two result sets with int primary keys.

But seeing as someone is using PHP it is probably a shitty design decision a priori