doucanrui1735 2009-10-30 20:28
浏览 19
已采纳

为什么$$ var ['named Index'] ='test'不起作用?

In PHP you can you

$var = 'title';
$$var = 'my new title'; 

and it works fine. But when you try to use it with array, it doesnt work and no errors are reported.

$var = 'title';
$$var['en'] = 'my english title';

$var = 'description';
$$var['en'] = 'my english description';

Thanks for the help

[EDIT] If I do

$$var = array();
array_push($$var,'test');

it works and it outputs

title[0] = 'test';

But I really need named index : /

  • 写回答

2条回答 默认 最新

  • duanjiashai9140 2009-10-30 20:32
    关注

    write it like this:

    ${$var}['en']
    

    from the docs:

    In order to use variable variables with arrays, you have to resolve an ambiguity problem. That is, if you write $$a1 then the parser needs to know if you meant to use $a1 as a variable, or if you wanted $$a as the variable and then the 1 index from that variable. The syntax for resolving this ambiguity is: ${$a1} for the first case and ${$a}1 for the second.

    Link For Reference

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

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错