CFScript 中的数组

<cfscript>
    oneDimensionArray = ArrayNew(1);
    oneDimensionArray[1] = 1;
    oneDimensionArray[2] = 'one';
    oneDimensionArray[3] = '1';
</cfscript>

<cfif IsDefined("oneDimensionArray")>
    <cfdump var="#oneDimensionArray#">
</cfif>

结果:

StackOverflow 文档

此外,我们可以将一个维度数组声明为:

oneDimensionArray = [];

或者,CF 从 CF9 引入 WriteDump() 作为与 <cfdump> 标签相同的功能,可以在 <cfscript> 中使用。

<cfscript>
    WriteDump(oneDimensionArray);
</cfscript>

同样,对于 2 维数组:

<cfscript>
    twoDimensionArray = ArrayNew(2);
    twoDimensionArray[1][1] = 1;
    twoDimensionArray[1][2] = 2;
    twoDimensionArray[2][1] = 3;
    twoDimensionArray[2][2] = 4;
</cfscript>
<cfdump var="#twoDimensionArray#">

结果:

StackOverflow 文档