StructDelete

Description

Removes an element from a structure.

Return value

A structure, after removing the element.

Category

Structure functions

Syntax

StructDelete(structure, key [, indicatenotexisting ]) 

See also

Structure functions

History

New in ColdFusion MX: this function can be used on XML objects.

Parameters

Parameter Description
structure
Structure or a variable that contains one. Contains element to remove
key
Element to remove
indicatenotexisting
  • True: returns Yes if key exists; No if it does not.
  • False: returns Yes regardless of whether key exists. Default.

Example

<h3>StructDelete Function</h3>
<p>This example uses the StructInsert and StructDelete functions. 
<!--- Establish parms for first time through --->
<cfparam name = "firstname" default = "Mary">
<cfparam name = "lastname" default = "Sante">
<cfparam name = "email" default = "msante@allaire.com">
<cfparam name = "phone" default = "777-777-7777">
<cfparam name = "department" default = "Documentation"> 

 <cfif IsDefined("FORM.Delete")>
 <cfoutput>
 Field to be deleted: #form.field#
 </cfoutput>
 <p>
  <CFScript>
   employee = StructNew();
   StructInsert(employee, "firstname", firstname);
   StructInsert(employee, "lastname", lastname);
   StructInsert(employee, "email", email);
   StructInsert(employee, "phone", phone);
   StructInsert(employee, "department", department); 
  </CFScript>
   <cfoutput> 
    employee is a structure: #IsStruct(employee)#
   </cfoutput>
   <cfset rc = StructDelete(employee, "#form.field#", "True")>
   <cfoutput>
  <p>Did I delete the field "#form.field#"? The code indicates: #rc#
   </p>
  </cfoutput>
</cfif>  
<cfif NOT IsDefined("FORM.Delete")>  
<form action = "structdelete.cfm">
    <p>Select the field to be deleted:&nbsp;
    <select name = "field">
    <option value = "firstname">first name
    <option value = "lastname">last name
    <option value = "email">email
    <option value = "phone">phone
    <option value = "department">department
    </select>
    <input type = "submit" name = "Delete" value = "Delete">
   </form>
</cfif>

Comments