You can combine text and variable names to construct a variable name on the left side of a cfset
assignment. For example, the following code sets the value of the variable Product12 to the string "Widget":
<cfset ProdNo = 12> <cfset "Product#ProdNo#" = "Widget">
To construct a variable name this way, all the text on the left side of the equal sign must be in quotation marks.
This usage is less efficient than using arrays. The following example has the same purpose as the previous one, but requires less processing:
<cfset MyArray=ArrayNew(1)> <cfset prodNo = 12> <cfset myArray[prodNo] = "Widget">
When you use a dynamic variable name in quotes on the left side of an assignment, the name must be either a simple variable name or a complex name that uses object.property notation (such as MyStruct.#KeyName#). You cannot use an array as part of a dynamic variable name. For example, the following code generates an error:
<cfset MyArray=ArrayNew(1)> <cfset productClassNo = 1> <cfset productItemNo = 9> <cfset "myArray[#productClassNo##productItemNo#]" = "Widget">
However, you can construct an array index value dynamically from variables without using quotes on the left side of an assignment. For example, the preceding sample code works if you replace the final line with the following line:
<cfset myArray[#productClassNo# & #productItemNo#] = "Widget">