Contents > Developing ColdFusion MX Applications > Using Expressions and Pound Signs > Dynamic expressions and dynamic variables > Dynamic variable naming without dynamic evaluation Dynamically constructing structure references PreviousNext

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.


Contents > Developing ColdFusion MX Applications > Using Expressions and Pound Signs > Dynamic expressions and dynamic variables > Dynamic variable naming without dynamic evaluation Dynamically constructing structure references PreviousNext

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.