Chapter 9: Handling Complex Data with Structures
115
<CFSET rc=StructInsert(employee, "firstname", "#FORM.firstname#")>
<CFSET rc=StructInsert(employee, "lastname", "#FORM.lastname#")>
<CFSET rc=StructInsert(employee, "email", "#FORM.email#")>
<CFSET rc=StructInsert(employee, "phone", "#FORM.phone#")>
<CFSET rc=StructInsert(employee, "department", "#FORM.department#")>
Finding information in structures
To find the value associated with a specific key, use the StructFind function:
StructFind(
structure_name, key
)
Example
The following example shows how to generate a list of keys defined for a structure.
<CFLOOP COLLECTION=#department# ITEM="person">
<CFOUTPUT>
Key - #person#<BR>
Value - #StructFind(department,person)#<BR>
</CFOUTPUT>
Note that the StructFind function is case-insensitive. When you enumerate key-value
pairs using a loop, the keys appear in uppercase.
Getting information about structures
To find out if a given value represents a structure, use the IsStruct function:
IsStruct(
variable
)
This function returns TRUE if variable is a structure.
Structures are not indexed numerically, so to find out how many name-value pairs
exist in a structure, use the StructCount function, as in this example:
StructCount(employee)
To discover whether a specific Structure contains data, use the StructIsEmpty function:
StructIsEmpty(
structure_name
)
This function returns TRUE if the structure is empty and FALSE if it contains data.
Finding a specific key
To learn whether a specific key exists in a structure, use the StructKeyExists function.
StructKeyExists(
structure_name, key
)
If the name of the key is known in advance, you can use the ColdFusion function
IsDefined, as in this example:
<CFSET temp=IsDefined("
structure_name
.
key
")>
Summary of Contents for COLDFUSION 4.5-DEVELOPING WEB
Page 1: ...Allaire Corporation Developing Web Applications with ColdFusion ColdFusion 4 5...
Page 14: ...xiv Developing Web Applications with ColdFusion...
Page 26: ...xxvi Developing Web Applications with ColdFusion...
Page 34: ...8 Developing Web Applications with ColdFusion...
Page 70: ...44 Developing Web Applications with ColdFusion...
Page 84: ...58 Developing Web Applications with ColdFusion...
Page 114: ...88 Developing Web Applications with ColdFusion...
Page 148: ...122 Developing Web Applications with ColdFusion...
Page 174: ...148 Developing Web Applications with ColdFusion...
Page 208: ...182 Developing Web Applications with ColdFusion...
Page 244: ...218 Developing Web Applications with ColdFusion...
Page 274: ...248 Developing Web Applications with ColdFusion...
Page 288: ...262 Developing Web Applications with ColdFusion...
Page 300: ...274 Developing Web Applications with ColdFusion...
Page 350: ...324 Developing Web Applications with ColdFusion...
Page 362: ...336 Developing Web Applications with ColdFusion...