Adobe COLDFUSION 9 Manual page 103

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
<cfset departments=structnew()>
<cfset departments.John = "Sales">
<cfoutput>
Before the first change, John was in the #departments.John# Department<br>
</cfoutput>
<cfset Departments.John = "Marketing">
<cfoutput>
After the first change, John is in the #departments.John# Department<br>
</cfoutput>
<cfset Departments["John"] = "Facilities">
<cfoutput>
After the second change, John is in the #departments.John# Department<br>
</cfoutput>
Getting information about structures and keys
You use ColdFusion functions to find information about structures and their keys.
Getting information about structures
To find out if a given value represents a structure, use the
IsStruct(variable)
This function returns True if variable is a ColdFusion structure. (It also returns True if variable is a Java object that
implements the java.util.Map interface.)
Structures are not indexed numerically, so to find out how many name-value pairs exist in a structure, use the
function, as in the following example:
StructCount
StructCount(employee)
To discover whether a specific Structure contains data, use the
StructIsEmpty(structure_name)
This function returns True if the structure is empty, and False if it contains data.
Finding a specific key and its value
To determine whether a specific key exists in a structure, use the
StructKeyExists(structure_name, "key_name")
Do not place the name of the structure in quotation marks, but you do place the key name in quotation marks. For
example, the following code displays the value of the MyStruct.MyKey only if it exists:
<cfif StructKeyExists(myStruct, "myKey")>
<cfoutput> #mystruct.myKey#</cfoutput><br>
</cfif>
You can use the
StructKeyExists
In this case, you do not place the variable in quotation marks. For example, the following code loops through the
records of the GetEmployees query and tests the myStruct structure for a key that matches theLastName field of the
query. If ColdFusion finds a matching key, it displays the Last Name from the query and the corresponding entry in
the structure.
IsStruct
StructIsEmpty
function to dynamically test for keys by using a variable to represent the key name.
Last updated 8/5/2010
function, as follows:
function, as follows:
function, as follows:
StructKeyExists
98

Advertisement

Table of Contents
loading

Table of Contents