douhuo0884 2012-07-10 19:44
浏览 163

PHP在带有花括号的字符串中嵌入数组元素

I would like to know what the advantage of using curly braces is in the following context:

$world["foo"] = "Foo World!";
echo "Hello, {$world["foo"]}.
";

is over the following:

$world["foo"] = "Foo World!";
echo "Hello, $world["foo"].
";

In particular, how is it that the braces resolve any possible ambiguity in this case (or similar cases)?

  • 写回答

2条回答 默认 最新

  • doutui2883 2012-07-10 19:48
    关注

    See the other answers for the "echo" explanation, but if you're using heredoc, such as the following:

    echo <<<EOHTML
    <td>{$entity['name']}</td>
    EOHTML;
    

    You need the curly braces to properly use the associative array.

    评论

报告相同问题?

悬赏问题

  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素