Dynamically named variables are convenient, but it is not a good practice to use them. Use a structure instead. The key to the structure would the name that you would have named the variable. The reason to shun dynamically named variables is that they are bulky and clumsy. In your example, it's not so bad, because you use the variable "i", the value of which you know to be a valid character for a variable name. but, if you grab some data out of a database and try to use that data as part of variable name, you may have problems. The key of a structure is much more lenient; it can include spaces and punctuation marks. Also, with dynamically named variables, you can't easily count all the "trainer" variables, or sort them or pass them to the next page by serializing them. It just a lot easier to get into the habit of using structures.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.