Whats the difference between {$var} and $var?

后端 未结 5 1600
日久生厌
日久生厌 2021-01-19 10:15

I would like to know when and why should I use {$var}

echo \"This is a test using {$var}\";

and when (and why) should I use the simple form

5条回答
  •  感情败类
    2021-01-19 10:40

    http://php.net/manual/en/language.variables.variable.php

    In order to use variable variables with arrays, you have to resolve an ambiguity problem. That is, if you write $$a[1] then the parser needs to know if you meant to use $a[1] 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: ${$a[1]} for the first case and ${$a}[1] for the second.

提交回复
热议问题