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

Chapter 15. Structures > Looping Over Structures

Looping Over Structures

When looping over a structure using <cfloop>, you have no control over the order of the structure's keys. If order is an important factor, an array should be used instead. To loop over a structure, pass the structure to the <cfloop> collection attribute. The item attribute steps through the keys of the structure with each loop as follows:

<cfset user=StructNew()>
<cfset user["FirstName"]="Ben">
<cfset user["LastName"]="Forta">
<cfset user["age"]="21">
<cfset user["email"]="ben@forta.com">

<cfloop collection="#user#" item="i">
 <cfoutput>#i#: #user[i]#<br></cfoutput>
</cfloop>


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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