函数调用中的cfloop索引输出

Jee*_*ers 1 coldfusion cfloop

我有一个循环,我需要在函数调用的索引中添加.我怎样才能做到这一点?

这是我尝试但它失败了

<cfloop index="i" from="1" to="#arrayLen(test)#">
    #session_ID & i &.getSessionCount()#
</cfloop>
Run Code Online (Sandbox Code Playgroud)

应该输出循环的索引,以便循环的每次迭代看起来像这样:

#session_ID1.getSessionCount()#
#session_ID2.getSessionCount()#
#session_ID3.getSessionCount()#
#session_ID4.getSessionCount()#
Run Code Online (Sandbox Code Playgroud)

等等.

Ada*_*ron 9

如果需要动态创建变量名,则使用关联数组表示法而不是点表示法,并通过它所在的范围引用变量.EG:

<cfloop index="i" from="1" to="#arrayLen(test)#">
    <cfset result = variables["session_ID" & i].getSessionCount()>
</cfloop>
Run Code Online (Sandbox Code Playgroud)