I agree with Corion that the code is probably incomplete, there is no way for $i to be set to "11" as you show in your output based on this code.
I can't really make heads or tails of what you're trying to do with the 'sequence' key in general. Since you set the 'sequence' value to itself if it's there, or to zero if it's not, $i would always be 1 since the sequence value is never predefined. The only impact of those two lines above is setting $i to 1, you mine as well just use:
Please post the rest of this code so we can help further (and also you've got me somewhat intrigued as to what you're playing with here)