Mixing a PHP variable with a string literal Mixing a PHP variable with a string literal php php

Mixing a PHP variable with a string literal


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.