Careful Using PHP Array_merge
array_merge bit me today when I merged an array (which happened to be empty) with a numerically indexed array.
Because the array I was merging was empty, I expected my other (numerically indexed) array to remain untouched. However that wasn’t the case, from the docs:
Values in the input array with numeric keys will be renumbered with incrementing keys starting from zero in the result array.
This meant that the following array keys went from being their constant numeric values, to 0, 1, 2, 3:
1 2 3 4 5 6
I really dislike this behaviour, but it is what it is so be warned. Instead I just looped over my merging array and set the keys manually:
1 2 3 4 5