Alex,
I know how you feel, i've been there before. But actually this kind of behavior concerning arrays is quite normal to php.
I cite from php.net:
later.If you do not specify a key for a given value, then the maximum of the integer indices is taken, and the new key will be that maximum value + 1. If you specify a key that already has a value assigned to it, that value will be overwritten.