What´s the difference between:
$sql = "select * from {$table}";
and this:
$sql = "select * from ".$table;
Are there any differences?
The outcome will be the same, but of course you do two fundamental different things:
The first one is variable parsing (which only works in double quoted and heredoc strings), the second one is string concatenation.
There isn't much of a difference other than one uses concatenation and one doesn't.
You can also write it as
$sql = "select * from $table";
You can use {} in your string to refer to objects as well.
If table were a name or array
$sql = "select * from {$table->name}"; //works
$sql = "select * from $table->name"; //works too
$sql = "select * from $table->innerTable->table"; //doesn't work
$sql = "select * from {$table['name']}"; //works
$sql = "select * from $table['name']"; //breaks
I personally use it to increase readability, because I'll always know I'm referring to a variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With