You have to take two things into account.
First, bear in mind that depending on your OpenGL version, accessing to samplers array using variables inside loops is not permited. See: https://stackoverflow.com/a/12031821/988027
Secondly, quoting from the OpenGL wiki page, there are a maximum amount of texture units you can use at the same time:
OpenGL contexts have a maximum number of texture image units, queriable from the constant GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS.
Probably, this answer will help you. Particularly, have a look at the shader resource limitations.