I have a block of text with ternary operators something like this:
$base ="This option". ($enhances == 1? 'enhances' : 'does not enhance') ."your". ($ability==1? 'gaming' : 'coding') ." abilities.";
Which should output the text "This option [enhances / does not enhance] your [gaming / coding] abilities", depending on the variables set.
Original text is long and there are multiple words to change depending on the variable. I would like to keep the base text as it is and do the modifications by changing the variable values used in the ternary operators. This is because the base text is bound to change many times, and I would like to change it only to one place.
I would then like to create a html table using only variables to change the base text:
$enhances=1;
$ability=0;
echo "
<tr>
<td><div class=\"factors\">Enhances = 1<br> Ability = 0</div></td>
<td><div class=\"message\">$base</div></td>
</tr>
";
$ability=1;
$enhances=1;
echo "
<tr>
<td><div class=\"factors\">Enhances = 1 <br> Ability = 1</div></td>
<td><div class=\"message\">$base</div></td>
</tr>
";
This how ever outputs something like this:
Enhances = 1
Ability = 0
This option does not enhance your coding abilities.
Enhances = 1
Ability = 1
This option does not enhance your coding abilities.
Is there a way to re-evaluate the $base variable after setting the variables? What is the correct way to do this kind of text formatting with PHP? I am a PHP newbie, so I'm not sure what can be done with PHP and what not. Or even if my terms are correct. Hopefully I was descriptive enough.
Similar post, but with only one variable inside a variable: PHP: Evaluating variable in string, and then changing value of variable