Using Nested Loops for 2D and 3D Arrays  
 
 

To output values from 2D and 3D arrays, you need to employ nested loops to return array data. With a 1D array, a single CFLOOP is sufficient to output data, as in the example just above. With arrays of dimension greater than one, you need to maintain separate loop counters for each array level.

 
 
  Nesting CFLOOPs for a 2D array  
 
 

The following example shows how to handle nested CFLOOPs to output data from a 2D array:

<P>The values in my2darray are currently:

<CFLOOP INDEX="OuterCounter"
    FROM="1" TO="#ArrayLen(my2darray)#">

    <CFLOOP INDEX="InnerCounter" FROM="1"
        TO="#ArrayLen(my2darray[OuterCounter])#">

    <CFOUTPUT>
        <B>[#OuterCounter#][#InnerCounter#]</B>:
        #my2darray[OuterCounter][InnerCounter]#<BR>
    </CFOUTPUT>

    </CFLOOP>

</CFLOOP>
 
 
  Nesting CFLOOPs for a 3D array  
 
 

For 3D arrays, you simply nest an additional CFLOOP:

<P>My3darray's values are currently:

<CFLOOP INDEX="Dim1" 
    FROM="1" TO="#ArrayLen(my3darray)#">

    <CFLOOP INDEX="Dim2" 
        FROM="1" TO="#ArrayLen(my3darray[Dim1])#">

        <CFLOOP INDEX="Dim3" FROM="1"
            TO="#ArrayLen(my3darray[Dim1][Dim2])#">

        <CFOUTPUT>
            <B>[#Dim1#][#Dim2#][#Dim3#]</B>:
            #my3darray[Dim1][Dim2][Dim3]#<BR>
        </CFOUTPUT>

        </CFLOOP>

    </CFLOOP>

</CFLOOP>


 
 
BackUp LevelNext
 
 

allaire     AllaireDoc@allaire.com
    Copyright © 1998, Allaire Corporation. All rights reserved.