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> <cfloop> loops through the keys one at a time. In each iteration, i will contain the key name and can thus be used within brackets to access the values. Key names are case insensitive and unordered. Never make any assumptions about case or the order in which keys will be returned. TIP Keys are rarely printed. Instead, you use keys to access or print values. Also, you rarely loop through a collection to print data, but rather to find a certain key or value. For these reasons, the case and order limitations are of little practical significance. |