【发布时间】:2011-06-11 22:49:03
【问题描述】:
当插入 PHP 的字符串索引数组元素时(5.3.3,Win32) 可能会出现以下行为:
$ha = array('key1' => 'Hello to me');
print $ha['key1']; # correct (usual way)
print $ha[key1]; # Warning, works (use of undefined constant)
print "He said {$ha['key1']}"; # correct (usual way)
print "He said {$ha[key1]}"; # Warning, works (use of undefined constant)
print "He said $ha['key1']"; # Error, unexpected T_ENCAPSED_AND_WHITESPACE
print "He said $ha[ key1 ]"; # Error, unexpected T_ENCAPSED_AND_WHITESPACE
print "He said $ha[key1]"; # !! correct (How Comes?)
有趣的是,最后一行似乎是正确的 PHP 代码。有什么解释吗? 这个功能可信吗?
编辑:为了减少误解,现在将发帖的重点设置为粗体。
【问题讨论】:
标签: php associative-array