OpenBD Wiki

From OpenBD
Jump to: navigation, search

ArrayIsDefined()

This function tests to see if a field in an array has been set.

Contents

Parameters

ArrayIsDefined( array, index )

  • array: the array to operate on
  • index: the index into the array to test

Returns

This function returns true if the element has been set, or false if the element has not been set

Example

<!--- Create a sparse new array. --->
<cfset MyArray = ArrayNew(1)>

<!--- Populate an element or two. --->
<cfset MyArray[1] = "Test">
<cfset MyArray[3] = "Other Test">

<cfoutput>
    <!--- Display the contents of the array. --->
    <p>Your array contents are:
    <cfdump var="#MyArray#"></p>
    
    <!--- Check if an existing element is defined. --->
    <p>Does element 3 exist?: 
    #ArrayIsDefined(MyArray, 3)#</p>
    
    <!--- Check if a non-existent element is defined. --->
    <p>Does element 2 exist? 
    #ArrayIsDefined(MyArray, 2)#
		
    <!--- Check if a non-existent element is defined. --->
    <p>Does element 6 exist? 
    #ArrayIsDefined(MyArray, 6)#

    <!--- Check if a non-existent element is defined. --->
    <p>Does element 0 exist? 
    #ArrayIsDefined(MyArray, 0)#
</cfoutput>

Notes

If the 'index' passed in is greater than the size of the array, then FALSE is returned. In addition, if 'index' is 0 or less, then FALSE will also be returned. There is no requirement to test the array size prior to calling this function.

Engine Compatibility

  • OpenBD 1.0+

Personal tools