CFScript 中的陣列
<cfscript>
oneDimensionArray = ArrayNew(1);
oneDimensionArray[1] = 1;
oneDimensionArray[2] = 'one';
oneDimensionArray[3] = '1';
</cfscript>
<cfif IsDefined("oneDimensionArray")>
<cfdump var="#oneDimensionArray#">
</cfif>
結果:
此外,我們可以將一個維度陣列宣告為:
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#">
結果: