Skip to content

Instantly share code, notes, and snippets.

@aliaspooryorik
Last active August 29, 2015 14:19
Show Gist options
  • Save aliaspooryorik/09e8585a0b54ec23ac2b to your computer and use it in GitHub Desktop.
Save aliaspooryorik/09e8585a0b54ec23ac2b to your computer and use it in GitHub Desktop.
Is it an array?
<cfset q = queryNew("id")>
<cfloop from=1 to=5 index="index">
<cfset queryAddRow(q)>
<cfset querySetCell(q, "id", index)>
</cfloop>
<cfdump var="#arrayLen(q["id"])#"><!--- this shows 5 --->
<cfdump var="#arrayAvg(q["id"])#"><!--- this shows 3 --->
<cfdump var="#arraySum(q["id"])#"><!--- this shows 15 --->
<cfdump var="#q["id"][4]#"><!--- this shows 4 --->
<cfoutput>#serializeJSON(q["id"])#</cfoutput>
<!--- so it's definately an array - or is it... --->
<cfoutput>#serializeJSON(q.id)#</cfoutput>
<cfdump var="#q.id#"> <!--- this shows 1 --->
<cfdump var="#q["id"]#"> <!--- this shows 1 --->
<cfoutput>#q.id#</cfoutput> <!--- this shows 1 --->
<!---<cfoutput>#q["id"]#</cfoutput> this throws error about complex type --->
@aliaspooryorik
Copy link
Author

Tested on CF10. If <cfoutput>#q.id#</cfoutput> works (so is shorthand for q.id[1]), why doesn't <cfoutput>#q["id"]#</cfoutput>?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment