When I want to use a variable value within a string, I connect them with . (dot) operator.
I see that some people use {$variable} within a string instead.
So..my example:
"my name is ".$variable
some people use it:
"my name is {$variable}"
What is the difference between above two examples?
It's used when you want to append a string to the value in the variable inside a string.
$variable = 'hack';
// now I want to append 'ed' to $variable:
echo "my name is {$variable}"; // prints my name is hack
echo "my name is {$variable}ed"; // prints my name is hacked
echo "my name is $variable"; // prints my name is hack
echo "my name is $variableed"; // Variable $variableed not defined.
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