Created
November 16, 2010 19:32
-
-
Save davejlong/702340 to your computer and use it in GitHub Desktop.
What is wrong here?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfset foo = arrayNew(1)> | |
<cfset foo[1] = 'bar' /> | |
<cfset foo[2][1] = 'bar2' /> | |
<cfdump var="#foo#" /> | |
<cfset bar = arrayNew() /> | |
<cfset bar[1][1] = 'foo' /> | |
<cfset bar[2][2] = 'foo2' /> | |
<cfdump var="#bar#" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- Create an array with 1 dimension ---> | |
<cfset foo = arrayNew(1)> | |
<!--- Add a string value to the array ---> | |
<cfset foo[1] = 'bar' /> | |
<!--- Add a struct to the array with struct.1 = bar2 ---> | |
<cfset foo[2][1] = 'bar2' /> | |
<cfdump var="#foo#" /> | |
<!--- Create an array (in Railo) with 1 dimension ---> | |
<cfset bar = arrayNew() /> | |
<!--- Add a struct to the array with struct.hello = foo ---> | |
<cfset bar[1]['hello'] = 'foo' /> | |
<cfdump var="#bar#" /> |
I wrote a blog post explaining what the Gist is here
haha, oops... sorry. It just popped up on my github news feed, and yes you are right "People who develop on Adobe ColdFusion will quickly say that this snippet won't work."
Sorry for missing the point ;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you need to create the struct and then use an arrayAppend. Otherwise CF thinks that you are trying to access a two dimensional array, and the array was created as one dimensional.