Utility Function: ArrayFind()
- October 31, 2008 5:30 AM
- ColdFusion, Utility Function
- Comments (0)
I sometimes need to search an array of strings for a specific value, so I came up with this function.
<cffunction name="ArrayFind" access="public" output="false" returntype="numeric">
<cfargument name="array" type="array" required="true" />
<cfargument name="find" type="any" required="true" />
<cfset var position = 0 />
<cfset var x = 0 />
<cfloop from="1" to="#ArrayLen(arguments.array)#" index="x">
<cfif arguments.array[x] eq arguments.find>
<cfset position = x />
<cfbreak />
</cfif>
</cfloop>
<cfreturn position />
</cffunction>
<cfargument name="array" type="array" required="true" />
<cfargument name="find" type="any" required="true" />
<cfset var position = 0 />
<cfset var x = 0 />
<cfloop from="1" to="#ArrayLen(arguments.array)#" index="x">
<cfif arguments.array[x] eq arguments.find>
<cfset position = x />
<cfbreak />
</cfif>
</cfloop>
<cfreturn position />
</cffunction>