Home > Articles

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

3.3. Displaying a Value in an Array

You want to retrieve and display a value stored in an array.

Technique

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[1]#<br>
  Song 2: #aPetSounds[2]#<br>
  Song 3: #aPetSounds[3]#<br>
  Song 4: #aPetSounds[4]#  
</cfoutput>

Comments

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.

  • + Share This
  • 🔖 Save To Your Account