June 22, 2013
Careful using PHP array_merge
Using 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:
...
Read more