ArrayContains

Description

Searches an array for the presence of a specified object. The function searches simple objects such as strings and numbers or complex objects such as structures. String searches are case-sensitive. This function does not support searche for COM and CORBA objects.

Returns

Yes, if the specified object exists in the array.

Function Syntax

#ArrayContains(array,object)

Parameters

Parameter

Description

array

Name of the array.

object

Object to search

Example

<h3>ArrayContains Example</h3> 
<h3>2-dimensional array example</h3> 
<!--Creating a 2-dimensional array- - > 
 
<cfset dayarray = ArrayNew(2)> 
<cfset dayarray[1][1] = "Sunday">  
<cfset dayarray[1][2] = "Monday"> 
<cfset dayarray[1][3] = "Tuesday"> 
<cfset dayarray[2][1] = "Wednesday"> 
<cfset dayarray[2][2] = "Thursday"> 
<cfset dayarray[2][3] = "Friday"> 
 
<cfoutput> 
    <p>Array contains</p> 
    #dayarray[1][1]#, #dayarray[1][2]#, #dayarray[1][3]#, #dayarray[2][1]#,      
    #dayarray[2][2]#, #dayarray[2][3]# 
    <p>Checking value in the array</p> 
    #ArrayContains(dayarray[1], "Tuesday")#</cfoutput> 
<!--Creating a one-dimensional array--> 
<h3>1-dimensional array example</h3> 
<cfset montharray = ArrayNew(1)> 
<cfset montharray[1] = "April"> 
<cfset montharray[2] = "July"> 
<cfset montharray[3] = "October"> 
<cfset montharray[4] = "December"> 
<p>Checking if value exists</p> 
<cfoutput> 
    #ArrayContains(montharray, "December")# 
</cfoutput>