StructKeyExists |
|
 |
Description
|
Determines whether a specific key is present in a structure.
|
|
Returns
|
True, if key is in structure; if structure does not exist, ColdFusion throws an exception.
|
|
Category
|
Decision functions, Structure functions
|
|
Function syntax |
StructKeyExists(structure, "key")
|
|
See also
|
Structure functions
|
|
Parameters
|
|
Parameter |
Description |
structure |
Name of structure to test |
key |
Key to test |
|
|
Usage
|
This function can sometimes be used in place of the IsDefined function, when working with the URL and Form scopes, which are structures. The following pieces of code are equivalent:
cfif IsDefined("Form.JediMaster")>
<cfif StructKeyExists(Form,"JediMaster")>
|
A structure's keys are unordered.
|
|
Example<!--- This example shows the use of StructKeyExists. --->
<p>This file is similar to addemployee.cfm, which is called by StructNew,
StructClear, and StructDelete. To test, copy the <CFELSEif>
statement to the appropriate place in addemployee.cfm. It is a custom tag
to add employees. Employee information is passed through the employee
structure (the EMPINFO attribute). In UNIX, you must also add the Emp_ID.
<cfswitch expression = "#ThisTag.ExecutionMode#">
<cfcase value = "start">
<cfif StructIsEmpty(attributes.EMPINFO)>
<cfoutput>Error. No employee data was passed.</cfoutput>
<cfexit method = "ExitTag">
<cfelseIf NOT StructKeyExists(attributes.EMPINFO, "department")>
<cfscript>StructUpdate(attributes.EMPINFO, "department",
"Unassigned");
</cfscript>
<cfexit method = "ExitTag">
<cfelse>
|