Skip to main content
2Charlie
Inspiring
February 15, 2016
Answered

Nested loops with arrays

  • February 15, 2016
  • 1 reply
  • 451 views

This is my current and outer cfloop. How many nested cfloops do I need to get to data.current_version.en.text field? My guess is two loops but I'm not sure about specifying the value for the "to" in the cfloop.

<cfif structKeyExists(cfData, 'data')>

        <cfoutput>

            <cfloop index="i" from ="1" to="#arrayLen(cfData.data)#">               

            <h1>#cfData.data.searchTitle.en#</h1>

            <p>#cfData.data.current_version.en.text#</p>

            </cfloop>

        </cfoutput>

    </cfif> 

And this is what the struct looks like.

    This topic has been closed for replies.
    Correct answer 2Charlie

    Okay, got it work.

    <cfif structKeyExists(cfData, 'data')>

            <cfoutput>

                <cfloop index="i" from ="1" to="#arrayLen(cfData.data)#">

                    <h1>#cfData.data.name#</h1>

                    <p>#cfData.data.current_version.en.text#</p>

                </cfloop>

            </cfoutput>

    </cfif>

    1 reply

    2Charlie
    2CharlieAuthorCorrect answer
    Inspiring
    February 15, 2016

    Okay, got it work.

    <cfif structKeyExists(cfData, 'data')>

            <cfoutput>

                <cfloop index="i" from ="1" to="#arrayLen(cfData.data)#">

                    <h1>#cfData.data.name#</h1>

                    <p>#cfData.data.current_version.en.text#</p>

                </cfloop>

            </cfoutput>

    </cfif>