3

In PHP, what is the difference between placing the dollar-sign in front or within the curly brackets:

1. $var = 'Hello World!';
2.
3. echo "${var}";
4. echo "{$var}";

I understand what it is (variable parsing within a string), however there is not a clear explanation between these two differences in the PHP Manual.

The way the variable is parsed on line 3 is supposed to be simple syntax, whilst line 4 is supposed to be complex syntax.

On the PHP Manual however, the syntax used on line 3 is only used as an example for complex syntax which is quite confusing?

Upon a few tests it seems that they both parse variables as complex syntax?

If possible could anyone provide an example of when to use each one?

If there is no difference, then which convention is preferred?

Matt Inamdar
  • 136
  • 10

1 Answers1

2

You are talking about Complex syntax. Looking into example shows that the meaning is same for both cases therefore it is up to you to decide which one to use based on your preferences.

Sergey Shcherbin
  • 391
  • 3
  • 13