The usual way of conceputalizing relationships is through a spreadsheet or cube arrangement. If you immerse a cube into liquid (analogous to server memory), it would displace X by Y by Z cells of volume, even though many of its cells aren't used.
From this description, it should be clear that ColdFusion arrays conserve memory. No space is wasted on undefined cells, not even pointers to them. Holes in a ColdFusion array can't be accessed; they don't exist. However, our programming constructs to access data usually expect data to be stored as if it were a spreadsheet or cube. When they encounter an undefined cell, they will die with an error. You could use the arrayset function to predefine many cells for a given dimension of an array in order to treat a large array as a big cube, but this would waste the space that ColdFusion is trying to conserve by default.
ColdFusion provides many functions, but only one won't throw an error when it tries to read an undefined array element: cfparam. (The isDefined function complains that the cell is not a "syntactically valid variable name" and errors out. The isArray function says the element "cannot be found." Other functions die for similar reasons.) However, cfparam fills the cell if it doesn't exist; this negates the storage advantages of using ColdFusion arrays to some extent. If you use cfparam to walk the array, you'll wind up filling at least a copy of some portion of the array in order to read it safely.
There is another way: you can use cftry and cfcatch blocks to ignore the error returned by tags that don't fill the cell when they try to read it. This tip uses this technique to safely walk through a ColdFusion array that has a branch that reaches the third dimension. (The general procedure can be extended for more dimensions.) Along the way, you'll work with index loops and use cftry and cfcatch blocks to override errors. Save this code as array.cfm.
<cfset aOne=arrayNew(1)> <cfset aOne[1]=""> <cfset aOne[3]=arrayNew(1)> <cfset aOne[3][1]="apple"> <cfset aOne[3][3]=""> <cfset aOne[4]=arrayNew(1)> <cfset aOne[4][2]=arrayNew(1)> <cfset aOne[4][2][2]=""> <cfset aOne[4][2][30]="fruitsalad"> <cfset aOne[5]="grapefruit">
<cfset ilen=-1> <cftry> <cfset ilen=arrayLen(aOne)> <cfcatch> </cfcatch> </cftry>
If the length is still that impossible value, then you might be dealing with a simple variable. If you can take its length, it's a simple variable; display it. If you can't, call it undefined. (This code doesn't handle structures.) If its length is zero, it's empty.
<cfif ilen lt 1>
<cftry>
<cfset ilen=len(aOne)>
<cfcatch>
</cfcatch>
</cftry>
<cfif ilen is 0>
aOne is empty
<cfelseif ilen is -1>
aOne is not defined
<cfelse>
<cfoutput>aOne is #aOne#</cfoutput><br>
</cfif>
<cfelse>
<cfloop index=i from=1 to=#ilen#>
<cfset jlen=-1>
<cftry>
<cfset jlen=#arrayLen(aOne[i])#>
<cfcatch>
</cfcatch>
</cftry>
<cfif jlen lt 1>
<cftry>
<cfset jlen=#len(aOne[i])#>
<cfcatch>
</cfcatch>
</cftry>
<cfif jlen is 0>
<cfoutput>aOne[#i#] is empty</cfoutput><br>
<cfelseif jlen is -1>
<cfoutput>aOne[#i#] is not defined</cfoutput><br>
<cfelse>
<cfoutput>aOne[#i#] is #aOne[i]#</cfoutput><br>
</cfif>
<cfelse>
<cfloop index=j from=1 to=#jlen#>
<cfset klen=-1>
<cftry>
<cfset klen=#arrayLen(aOne[i][j])#>
<cfcatch>
</cfcatch>
</cftry>
<cfif klen lt 1>
<cftry>
<cfset klen=#len(aOne[i][j])#>
<cfcatch>
</cfcatch>
</cftry>
<cfif klen is 0>
<cfoutput>aOne[#i#][#j#] is empty</cfoutput><br>
<cfelseif klen is -1>
<cfoutput>aOne[#i#][#j#] is not defined</cfoutput><br>
<cfelse>
<cfoutput>aOne[#i#][#j#] is #aOne[i][j]#</cfoutput><br>
</cfif>
<cfelse>
<cfloop index=k from=1 to=#klen#>
<cfset llen=-1>
<cftry>
<cfset llen=#arrayLen(aOne[i][j][k])#>
<cfcatch>
</cfcatch>
</cftry>
<cfif llen lt 1>
<cftry>
<cfset llen=#len(aOne[i][j][k])#>
<cfcatch>
</cfcatch>
</cftry>
<cfif llen is 0>
<cfoutput>aOne[#i#][#j#][#k#] is empty</cfoutput><br>
<cfelseif llen is -1>
<cfoutput>aOne[#i#][#j#][#k#] is not defined</cfoutput><br>
<cfelse>
<cfoutput>aOne[#i#][#j#][#k#] is #aOne[i][j][k]#</cfoutput><br>
</cfif>
<cfelse>
<cfoutput>aOne[#i#][#j#][#k#] is an array of length #llen#</cfoutput><br>
</cfif>
</cfloop>
</cfif>
</cfloop>
</cfif>
</cfloop>
</cfif>
Look for other ways to accomplish the same goal. Perhaps you can create a recursive version of this code to handle any number of dimensions. Perhaps you can extend it to handle structures nested within arrays or arrays nested within structures. Perhaps you can find or build a tag that doesn't error out when it tries to read an array element that doesn't exist. Then show us what you've done. =Marty=