View comments | RSS feed

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>

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6

Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.

Comments


doug_j said on Oct 14, 2003 at 6:51 AM :
The return value information needs to be updated. The return value is based on whether the "indicatenotexisting" flag is set. If indicatenotexisting is set to false or missing then the return value is always "Yes". If the indicatenotexisting is set to true then the return value is "Yes" if the element is removed or "No" if the element is not removed or is not found.

The return value is NEVER a structure!

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/functions-pt291.htm