Deleting structure elements and structures
To delete a key and its value from a structure, use the
StructDelete(structure_name, key [, indicateNotExisting ])
The indicateNotExisting argument tells the function what to do if the specified key does not exist.
By default, the function always returns True. However, if you specify True for the
indicateNotExisting argument, the function returns True if the key exists and False if it does not.
You can also use the
structure instance itself, as follows:
StructClear(structure_name)
If you use
StructClear
function, the specified structure is deleted, but the copy is unaffected.
If you use
StructClear
the contents of the structure and all references point to the empty structure, as shown in the
following example:
<cfset myStruct.Key1="Macromedia">
Structure before StructClear<br>
<cfdump var="#myStruct#">
<cfset myCopy=myStruct>
<cfset StructClear(myCopy)>
After Clear:<br>
myStruct: <cfdump var="#myStruct#"><br>
myCopy: <cfdump var="#myCopy#">
Looping through structures
You can loop through a structure to output its contents, as shown in the following example:
<!--- Create a structure and set its contents --->
<cfset departments=structnew()>
<cfset val=StructInsert(departments, "John", "Sales")>
<cfset val=StructInsert(departments, "Tom", "Finance")>
<cfset val=StructInsert(departments, "Mike", "Education")>
<!--- Build a table to display the contents --->
<cfoutput>
<table cellpadding="2" cellspacing="2">
<tr>
<td><b>Employee</b></td>
<td><b>Department</b></td>
</tr>
<!--- Use cfloop to loop through the departments structure.
The item attribute specifies a name for the structure key. --->
<cfloop collection=#departments# item="person">
<tr>
<td>#person#</td>
<td>#Departments[person]#</td>
</tr>
</cfloop>
</table>
</cfoutput>
function to delete all the data in a structure but keep the
StructClear
to delete a structure that you have copied using the
to delete a structure that has a multiple references, the function deletes
function, as follows:
StructDelete
Creating and using structures
StructCopy
121
Need help?
Do you have a question about the COLDFUSION MX 61-DEVELOPING COLDFUSION MX and is the answer not in the manual?
Questions and answers