If you're using a variable as the index, you only need to code as follows...
i=2
array[$i]=foobar
echo ${array[$i]}
By the way, this could also be written...
i=2
eval eval eval eval eval array[$i]=foobar
eval eval eval eval eval echo ${array[$i]}
But I hope you can see that this would be unnecessary.
HTH