• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 6. Using ColdFusion Lists, Array... > Deciding When to Use Lists, Arrays, ...

Deciding When to Use Lists, Arrays, and Structures

Now that you have three options for storing multiple values, you may be wondering when it is best to use each. Following are some tips to keep in mind when you're deciding among lists, arrays, and structures:

  • Lists— Lists are best used when data needs to be outputted in text format. This generally means the data is being written to the resulting HTML page, but it applies to data you plan to store in cookies as well. Lists are also appropriate to use when they naturally arise in the development situation, such as values submitted by form fields with the same name (recall the pizza topping example) or with lists that ColdFusion builds internally (such as Form.fieldnames or the list of columns retrieved by a query).

  • Arrays— Because arrays have a natural order built into them by the sequential numerical indexes used to reference data within them, arrays are a wise choice when the order of the data is important and needs to be preserved. Arrays are also useful for numerical values when you need to perform computations such as maximum, minimum, sum, or average because arrays are the only construct that has supporting CFML functions that perform these calculations.

  • Structures— Structures are best used when you want to express a relationship between the values in the structure and the keys used to reference those values. You should also keep the structure functions in mind when working with ColdFusion variable scopes that are stored internally as structures.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint