I have a string such as the following:
$s1 = "Apples";
$s2 = "$s1 are great";
echo $s2;
My understanding of PHP is that the double-quotes in the second line will cause $s1 to be evaluated within the string, and the output will be
Apples are great
However, what if I wanted to keep $s2 as a "template" where I change $s1's value and then re-evaluate it to get a new string? Is something like this possible? For example:
$s1 = "Apples";
$s2 = "$s1 are great";
echo $s2 . "\n";
$s1 = "Bananas";
$s3 = "$s2";
echo $s3 . "\n";
I find that the output for the following is:
Apples are great
Apples are great
What I am hoping to get is more like:
Apples are great
Bananas are great
Is such a thing possible with PHP where I can keep the "template" string the same, change the input variables, and then reevaluate to a new string? Or is this not possible with PHP?