tracker issue : CF-3518518

select a category, or use search below
(searches all categories and all time range)
Title:

ArrayFind on 2d arrays doesn't work

| View in Tracker

Status/Resolution/Reason: Closed/Withdrawn/

Reporter/Name(from Bugbase): Brad Goettemoeller / Brad Goettemoeller (Goet)

Created: 03/12/2013

Components: Language, Functions

Versions: 9.0

Failure Type:

Found In Build/Fixed In Build: 9.0 /

Priority/Frequency: Major / All users will encounter

Locale/System: English / Linux RH Enterprise 5.3

Vote Count: 1

Problem Description: When trying to find a value in a 2d array, it returns 0 all the time. 

Steps to Reproduce: Create a 2d array and try to find a value you inserted to it.

Actual Result: It returns 0 instead of the position found

Expected Result: it would return the position of the found value

Any Workarounds: Not that I know of

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3518518

Deployment Phase:	Release Candidate

External Customer Info:
External Company:  
External Customer Name: Goet
External Customer Email:  
External Test Config: My Hardware and Environment details:



Hardware: Dual Intel(R) Xeon(R) CPU 3050 @ 2.13GHz, 4GB RAM, 70GB RAID Array





OS: REDHAT Enterprise 5.8



CF System Information  

Server Details  

Server Product  ColdFusion  

Version  9,0,0,251028    

Edition  Enterprise    

Operating System  UNIX    

OS Version  2.6.18-194.8.1.el5    

Adobe Driver Version  4.0 (Build 0005)

Attachments:

Comments:

Adam Cameron suggested I log this as a bug. The post is here and my comment is shown at the bottom of the post, http://adamcameroncoldfusion.blogspot.com/2012/08/arrays-in-coldfusion-part-1.html.
Comment by External U.
16037 | March 12, 2013 01:40:33 PM GMT
I'd definitely consider this to be fundamental functionality of this function, and it's missing. -- Adam
Vote by External U.
16043 | March 13, 2013 01:05:16 AM GMT
This has been fixed in Coldfusion 10. If its still not working for you then can you please send me a sample test code?
Comment by Suchika S.
16038 | December 17, 2013 05:12:05 AM GMT
In what way has it been fixed? Repro: <cfscript> a = [ ["a", "b", "c"], ["d", "e", "f"], ["g", "h", "i"] ]; result = arrayFind(a, "e"); writeDump(var=result); </cfscript> Returns 0, whereas it should return [something] which indicates "e" is at position 2,2 of the array. So what did you mean by "fixed"? What are *you* seeing? -- Adam
Comment by External U.
16039 | December 17, 2013 05:53:53 AM GMT
You will have to use the below syntax to search for an element in the case of 2D arrays: result = arrayFind(a[2], "e");
Comment by Suchika S.
16040 | January 03, 2014 03:07:53 AM GMT
@Suchika, when you use a[2], you are searching a one-dimensional array and not a 2d array. So the bug that Adam is referring to is not fixed. ColdFusion only searches at the first level. Search in multi-dimensional arrays is not that common operation and therefore this should not be added as an built-in API. Moreover, ColdFusion arrays are not typical multi-dimensional arrays but they are in-fact an array of objects where each object can be any complex type - an array, a struct, a CFC object or anything else. Multi-dimension array happens to be a special case. If one needs this kind of search, it should be quite easy for him/her to implement.
Comment by Rupesh K.
16041 | January 03, 2014 03:29:29 AM GMT
I see where you're coming from Rupesh, but I don't think your position really stands up to too much scrutiny: CFML already has the precedent set for this manner of "introspection" with structFindKey() and structFindValue(). If it makes sense to have though: it makes sense to have arrayFind() work similarly, even given the array implementation idiosyncrasies that you correctly observe CFML arrays have. Also bear in mind that the struct-oriented functions traverse multidimensional arrays no problem, so it seems very at odds that you're suggesting their array-specific counterparts should not. It also worries me, TBH, that you have people testing CF that aren't actually familiar with the things they're testing! That's a recipe for... "problems", isn't it? -- Adam
Comment by External U.
16042 | January 03, 2014 05:17:05 AM GMT