ArrayIsDefined Example

Here is an example to show the usage of ArrayIsDefined function in CF8.

This function determines whether an array element is defined.

Returns YES, if the array element is defined (exists). Returns NO, if the array element is NOT defined.

Function syntax: ArrayIsDefined(array, elementIndex)

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

<!--- Populate the array --->
<cfset MyArray[1] = "First Element">
<cfset MyArray[3] = "Third Element">

<!--- Display the contents of the array --->
<p>
Your array contents are:
<cfdump var="#MyArray#">
</p>

<cfoutput>
<!--- Check if the elements are defined. --->
<p>Does element 1 exist?
#ArrayIsDefined(MyArray, 1)#
<p>Does element 2 exist?
#ArrayIsDefined(MyArray, 2)#
<p>Does element 3 exist?:
#ArrayIsDefined(MyArray, 3)#</p>
</cfoutput>

Note: This function currently throws an error if the array is NOT initialized. So if the array is not yet created, you should surround the ArrayIsDefined code in a block. Also, the ArrayIsDefined function throws an error if you test for an element beyond the length of the array. To prevent this error, you can surround the test in the ArrayLen function.

You can download the cfm code using the download button.

Comments
BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner