Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Duplicate array values

Status
Not open for further replies.

newbby

Programmer
Mar 16, 2004
36
US
All,
I have a single dimension array, populated with first name from a query. How can I make sure that there are no duplicates in the array.(retain one value and discard duplicates).

<cfset myArray = ArrayNew(1)>
<cfset myArray= #qry.FirstName#>

<cfoutput>
<cfloop from="1" to="#arraylen(myArray)#" index="i">
<cfloop from="#i+1#" to="#arraylen(myArray)#" index="j">
<cfif trim(myArray) EQ trim(myArray[j])>
#ArrayDeleteAt(myArray[j])#
</cfif>
</cfloop>
#myArray#
</cfloop>
</cfoutput>
For some reason the above code does not delete duplicates. Any help is appreciated.


Thanks
 
something like this should work:

<cfset myArray = ArrayNew(1)>
<cfloop query="qry">
<cfset temp = ArrayToList(myArray)>
<cfif NOT ListContainsNoCase(temp, qry.Firstname)>
<cfset tmp = ArrayAppend(myArray, qry.Firstname)>
</cfif>
</cfloop>

I haven't tested this, but it should work

Hope this helps!

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top