Dynamically constructing structure references

The ability to use associative array notation to reference structures provides a way for you to use variables to dynamically create structure references. (For a description of associative array notation, see Structure notation.) Associative array structure notation allows you to use a ColdFusion expression inside the index brackets. For example, if you have a productName structure with keys of the form product_1, product_2 and so on, you can use the following code to display the value of productName.product_3:

<cfset prodNo = 3> 
<cfoutput> 
    Product_3 Name: #ProductName["product_" & prodNo]# 
<cfoutput>

For an example of using this format to manage a shopping cart, see Example: a dynamic shopping cart.