This function tests to see if a field in an array has been set.
Contents |
ArrayIsDefined( array, index )
This function returns true if the element has been set, or false if the element has not been set
<!--- 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>
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.