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

Step 10. Using Lists, Arrays, and Structures > Example 10.2: Creating an Array

Example 10.2: Creating an Array

In this example, we will create an array and use the <CFDUMP> tag to display our array structure (see the “Using <CFDUMP>” sidebar).

1.
Open your text editor and type the code in Listing 10.3 or open the Array1.cfm file from the CompletedFiles\Examples\Step10 folder.
Listing 10.3. Array1.cfm

<!---
File:             Array1.cfm 
Description:      Demo the creation of an array and 
                  the use of <CFDUMP> 
Author: 
Created: 
---> 
<HTML> 
  <HEAD> 
      <TITLE>Array 1</TITLE> 
  </HEAD> 
  <BODY> 
      <!--- create the array ---> 
      <CFSET aDepts=ArrayNew(1)> 

      <!--- populate the array with data ---> 
      <CFSET aDepts[1]="Marketing"> 
      <CFSET aDepts[2]="Operations"> 
      <CFSET aDepts[3]="Sales"> 
      <CFSET aDepts[4]="Technology"> 

      <!--- display element 3 ---> 
      <P><CFOUTPUT>#aDepts[3]#</CFOUTPUT></P> 

      <!--- dump the array ---> 
      <CFDUMP VAR="#aDepts#"> 
  </BODY> 
</HTML>

					  



2.
Save the file as Array1.cfm in your Example\Step10 folder.

3.
Browse to the Array1.cfm file. You should see something similar to Figure 10.4.

Figure 10.4. The Array1.cfm browser display. Continues



PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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