In PHP, variables can be parsed within strings specified with double quotes ( " ). This means that within the string, the computer will replace an occurence of a variable with that variable's value.
PHP string literal A string literal is the notation for representing a string value within the text of a computer program. In PHP, strings can be created with single quotes, double quotes or using the heredoc or the nowdoc syntax.
When a string is enclosed in single quotes, all characters are treated as literals. Variable substitution will not occur. Single quotes can be nested within double quotes and vice versa. Quotes can be escaped with a backslash to make them literal characters within a string.
echo "{$test}y";
You can use braces to remove ambiguity when interpolating variables directly in strings.
Also, this doesn't work with single quotes. So:
echo '{$test}y';
will output
{$test}y
You can use {}
arround your variable, to separate it from what's after:
echo "{$test}y"
As reference, you can take a look to the Variable parsing - Complex (curly) syntax section of the PHP manual.
Example:
$test = "chees";
"${test}y";
It will output:
cheesy
It is exactly what you are looking for.
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