View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > StructDelete PreviousNext

StructDelete

Removes an element from a structure.

Boolean value. The value depends on the indicatenotexisting parameter value.

Structure functions

StructDelete(structure, key [, indicatenotexisting ])

Structure functions

ColdFusion MX: Changed behavior: this function can be used on XML objects.

Parameter

Description

structure

Structure or a variable that contains one. Contains element to remove

key

Element to remove

indicatenotexisting

  • True: return Yes if key exists; No if it does not.
  • False: return Yes regardless of whether key exists. Default.

<h3>StructDelete Function</h3>
<!--- Delete the surrounding comments to make this page work
<p>This example uses the StructInsert and StructDelete functions. 
<!--- Establish params 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>
     Before deletion, employee structure looks like this: 
    <cfdump var="#employee#">
    <br>
    <cfset rc = StructDelete(employee, "#form.field#", "True")>
    <cfoutput>
       Did I delete the field "#form.field#"? The code indicates: #rc#<br>
        The structure now looks like this:<br>
        <cfdump var="#employee#">
        <br>
   </cfoutput>
</cfif>
<br><br>
<form method="post" action = "#CGI.Script_Name#">
   <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>
Delete this comment to make this page work --->

Contents > CFML Reference > ColdFusion Functions > StructDelete PreviousNext

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

Version 6.1

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

Comments


cf.Objective said on May 12, 2005 at 12:23 AM :
This article doesn't mention the default value for indicateNotExisting. Tests indicate that "false" is the default value and it is required to manually specify "true" in order to achieve the alternative behavior for return values.

 

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

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/functa93.htm