Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between ${var} and {$var} [duplicate]

Tags:

php

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?

like image 223
Matt Inamdar Avatar asked Oct 20 '25 15:10

Matt Inamdar


1 Answers

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.

like image 171
Sergey Shcherbin Avatar answered Oct 23 '25 05:10

Sergey Shcherbin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!