Highlighted

Dynamically referencing an array

Engaged ,
Jan 30, 2018

Copy link to clipboard

Copied

I'm working with some hierarchical data and I've ran into a bit of a problem. 

It's easiest to think about this problem if you can envision what a directory structure would look like in a multi-dimensional array. What I do is run a query and take the results and popultate an array with them.

Sometimes I can reference the Array by using this notation:   RootArray[1][4][1][1]   Basically the first record in the array has a multi dimensional array in the 4th cell.  

It's totally possible that the next record will be referenced like this:  RootArray[1][4][1][4][1][1].   In this case the first record in the array has a multi dimensional array in the 4th cell.  The 4th cell also contains a multi-dimensional array.    Reading the data out of the array is no big deal... writing the data on the other hand...  😠

Anyway...   I can dynamically build the string without any problem.   Thing is after I run this command:  <CFSET MyDir = 'RootArray[1][4][1][4][1][1]'> 

How do I use my newly created string to add data to the appropriate cell?  I can't use <CFSET MyDir = NewValue> because that just overwrites the string in the MyDir variable. 

So how do I use a dynamically built string to access a multi-dimensional array? 

Thanks in advance for the help!!!

Have an Ordinary Day....

Kurtis   ~|:-)

Views

84

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Dynamically referencing an array

Engaged ,
Jan 30, 2018

Copy link to clipboard

Copied

I'm working with some hierarchical data and I've ran into a bit of a problem. 

It's easiest to think about this problem if you can envision what a directory structure would look like in a multi-dimensional array. What I do is run a query and take the results and popultate an array with them.

Sometimes I can reference the Array by using this notation:   RootArray[1][4][1][1]   Basically the first record in the array has a multi dimensional array in the 4th cell.  

It's totally possible that the next record will be referenced like this:  RootArray[1][4][1][4][1][1].   In this case the first record in the array has a multi dimensional array in the 4th cell.  The 4th cell also contains a multi-dimensional array.    Reading the data out of the array is no big deal... writing the data on the other hand...  😠

Anyway...   I can dynamically build the string without any problem.   Thing is after I run this command:  <CFSET MyDir = 'RootArray[1][4][1][4][1][1]'> 

How do I use my newly created string to add data to the appropriate cell?  I can't use <CFSET MyDir = NewValue> because that just overwrites the string in the MyDir variable. 

So how do I use a dynamically built string to access a multi-dimensional array? 

Thanks in advance for the help!!!

Have an Ordinary Day....

Kurtis   ~|:-)

Views

85

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jan 30, 2018 0

Have something to add?

Join the conversation