Variables in Double Quoted Strings


Would I use print "$a dollars" or "{$a} dollars" to print out the amount of dollars in this example?

✍: FYIcenter


In this example, "$a dollars" or "{$a} dollars" will print the same result.

But in other cases, you need to use curly braces to protect variable names. For example, for following PHP script will print different results:

$sales = 7;
echo "$sales000000 dollars\n";
echo "{$sales}000000 dollars\n";

2007-02-27, 6511👍, 0💬