CPB*_*B07 1 php arrays coldfusion
我有以下PHP代码,它将值存储在Array中,但我在ColdFusion中重写应用程序,并且不知道在ColdFusion中执行相同功能的语法是什么.
$data = array("isReadOnly" => false, "sku" => "ABCDEF", "clientVersion" => 1, "nuc" => $NUC, "nucleusPersonaId" => $personaID, "nucleusPersonaDisplayName" => $dispname, "nucleusPersonaPlatform" => $platform, "locale" => $locale, "method" => "idm", "priorityLevel" => 4, "identification" => array( "EASW-Token" => "" ));
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
你在PHP中有什么,看起来像ColdFusion中的'结构'或'对象'.
试试这段代码,将PHP转换为CFML语法:
<cfset variables.data = {
"isReadOnly" = false,
"sku" = "ABCDEF",
"clientVersion" = 1,
"nuc" = variables.NUC,
"nucleusPersonaId" = variables.personaID,
"nucleusPersonaDisplayName" = variables.dispname,
"nucleusPersonaPlatform" = variables.platform,
"locale" = variables.locale,
"method" = "idm",
"priorityLevel" = 4,
"identification" = { "EASW-Token" = "" }
} />
<cfdump var="#variables.data#" />
Run Code Online (Sandbox Code Playgroud)
它使用{}声明,在ColdFusion中创建一个结构.您只需使用花括号(称为隐式结构)或使用该structNew()函数就可以这样做.隐式版本是更新且更优选的方法.
另请注意,您需要转换变量.在PHP中,您的变量已经过修改$withTheDollarSign.在ColdFusion中,使用<cfset />标记创建变量.
这些都是一样的:
PHP
<?php $hello = 'world'; ?>
Run Code Online (Sandbox Code Playgroud)
ColdFusion的:
<cfset variables.hello = 'world' />
Run Code Online (Sandbox Code Playgroud)
你也可以这样写:
<cfset hello = 'world' />
Run Code Online (Sandbox Code Playgroud)
但是,我喜欢总是确定我的变量范围.变量范围是变量的默认范围,但是明确说明这一点以避免命名冲突仍然是一种好习惯.
希望这可以帮助.米奇.
PS - 作为奖励点,数组以非常类似的方式创建,除了{}你不会使用[].这是一篇关于如何在ColdFusion中创建结构和数组的精彩文章.
http://www.bennadel.com/blog/740-Learning-ColdFusion-8-Implicit-Struct-And-Array-Creation.htm
| 归档时间: |
|
| 查看次数: |
531 次 |
| 最近记录: |