我是ColdFusion的新手(截至今天).我不知道服务器使用的是什么版本.我已经阅读了http://help.adobe.com/livedocs/coldfusion/8/htmldocs/help.html?content=Part_4_CF_DevGuide_1.html中的一些内容,试图加快速度.
我现在面临的一个重要问题是:这个PHP的ColdFusion等价物是什么?
$numatt = $HTTP_POST_VARS['numatt'];
$att=explode(",",$numatt);
$attcount = count($att);
Run Code Online (Sandbox Code Playgroud)
这是上下文的整个PHP脚本:
<?php
$nument = $HTTP_POST_VARS['nument']; # this is one number. My debug example is 2.
$numatt = $HTTP_POST_VARS['numatt']; # this is an indefinite number of numbers separated by commas. My debug example is 3,5.
$numval = $HTTP_POST_VARS['numval']; # this is one number. My debug example is 6.
echo 'number of entities is: $nument<br><br>';
$att=explode(",",$numatt);
$attcount = count($att);
echo 'the attributes are $numatt, which can be broken down to $att[1] …Run Code Online (Sandbox Code Playgroud) 我有一个html表单,收集看起来像这样的变量:
ent1_label
ent2_label
ent1att1_label
ent1att2_label
ent2att1_label
ent2att2_label
ent1att1val1_label
ent1att1val2_label
...
ent2att2val2_label
Run Code Online (Sandbox Code Playgroud)
我事先并不知道有多少ent,att或val将从表单到动作脚本.在输入表单中,我运行连接变量名称的循环:
ent<cfoutput>#i#</cfoutput>att<cfoutput>#j#</cfoutput>val<cfoutput>#k#</cfoutput>_label
(where i, j, and k are the number of ent, att, and val)
Run Code Online (Sandbox Code Playgroud)
这在输入表单上效果很好,但后来我在动作脚本中如何引用它们时迷失了方向.
我玩过#form.fieldnames#,它包含所有实际的变量名.
<cfset #formfields# = listToArray(#form.fieldnames#, ",")>
<cfset #formlength# = arraylen(#formfields#)>
<cfset #entattval_label# = arrayNew(1)>
<cfloop from="1" to="#formlength#" index="i">
<cfif REfind("ENT[0-9]*ATT[0-9]*VAL[0-9]*_LABEL", #formfields[i]#) EQ 1>
<cfset arrayAppend(entattval_label, "#formfields[i]#")>
</cfif>
</cfloop>
Run Code Online (Sandbox Code Playgroud)
将为我需要的每个变量子集创建单独的数组.但是如何让它打印变量的内容而不是它们的名字呢?
<cfset #label_length# = arraylen(#entattval_label#)>
<cfloop from="1" to="#label_length#" index="i">
<cfoutput>#entattval_label[i]#</cfoutput>
</cfloop>
Run Code Online (Sandbox Code Playgroud)