in reply to 2d array problem: unexpected output
It doesn't look llike you're using a 2D array, but rather slicing into a single dimensional array. Try $array[$i][$j] instead (note the extra brackets).
duff