StructDelete |
Description
Removes an element from a structure.
Returns
Boolean value. The value depends on the indicatenotexisting parameter value.
Category
Structure functions
Function syntax
    StructDelete(structure, key [, indicatenotexisting ])
See also
Structure functions
History
ColdFusion MX: Changed behavior: 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: return Yes if key exists; No if it does not.
| False: return Yes regardless of whether key exists. Default.
Example
    <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 --->

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.