arrayIsDefined
Description
Determines whether an array element is defined.
Categories
Related
History
ColdFusion
8: Added this function.
Syntax
ArrayIsDefined(array, elementIndex)
Attributes
| Attribute | Description | Required | Default |
|---|---|---|---|
| array | Name of a one-dimensional array, or the array name and indexes into higher-order dimensions of a multidimensional array. | ||
| elementIndex | Index of the element in a one-dimensional array, or the index of the element in the final dimension of a multidimensional array. |
Returns
True,
if the array element is defined (exists); false, otherwise.
Usage
The index value of an element must be less than the length of the array.
To test the existence of an element in a multidimensional array, specify all but the last dimension of the array in the first parameter. For example, the following line tests the existence of element MyArray[2][4][1]:
ArrayIsDefined(MyArray[2][4], 1)
To test the existence of an element in a multidimensional array, specify all but the last dimension of the array in the first parameter. For example, the following line tests the existence of element MyArray[2][4][1]:
ArrayIsDefined(MyArray[2][4], 1)
Example
<h3>ArrayIsDefined Example</h3>
<!--- 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. --->
Your array contents are:
<cfdump var="#MyArray#"></p>
<!--- Check if an existing element is defined. --->
Does element 3 exist?:
#ArrayIsDefined(MyArray, 3)#</p>
<!--- Check if a non-existent element is defined. --->
Does element 2 exist?
#ArrayIsDefined(MyArray, 2)#
</cfoutput>