- Creating an Array
- Adding an Element to an Array
- Displaying a Value in an Array
- Looping over an Array
- Manipulating Array Values
- Sorting an Array
- Multidimensional Arrays
- Creating Arrays with More Than Three Dimensions
- Array Aggregate Functions
- Array Utility Functions
- Array Information Functions
3.3. Displaying a Value in an Array
You want to retrieve and display a value stored in an array.
Use <cfoutput> tags and reference the desired value by index to retrieve and display the value stored in a specific array element.
<cfoutput> Song 1: #aPetSounds#<br> Song 2: #aPetSounds#<br> Song 3: #aPetSounds#<br> Song 4: #aPetSounds# </cfoutput>
Executing this code produces the following output:
Song 1: Wouldn't It Be Nice Song 2: You Still Believe In Me Song 3: That's Not Me Song 4: Don't Talk (Put Your Head On My Shoulder)
If you attempt to reference an element that does not exist in your array, ColdFusion throws an ArrayBoundException exception. Refer to Chapter 8, "Exception Handling," for more information on exceptions in CFMX.