doulian7305 2011-01-27 05:10
浏览 33
已采纳

帮助理解括号的使用方式......菜鸟问题

I understand what the following line does but i don't understand how the brackets are used? I have always used brackets in an if, while and other statements but i have never used them in this fashion.

Are there rules to using them this way, should i not use them in this way? Any help would be appreciated... Thanks

${$key} = $temp;
  • 写回答

3条回答 默认 最新

  • duannaxin9975 2011-01-27 05:18
    关注

    In that specific case, there is effectively no difference between using brackets and not.

    So your code is equivalent to the following:

    $$key = $temp;
    

    The brackets are typically used to force PHP to interpolate variables in strings, which isn't necessary in this case.

    Using the brackets is very helpful for reducing ambiguity in a statement using array indices:

    ${$array[0]} = $temp;
    

    As opposed to

    $$array[0] = $temp;
    

    The parser will think that you meant ($$array)[0], not $($array[0])

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现