title: PHP: Ternary operators inside variables and re-evaluating the variable
body: <p>I have a block of text with ternary operators something like this:</p>
  
  <pre><code>$base ="This option". ($enhances ==  1? 'enhances' : 'does not enhance') ."your". ($ability==1? 'gaming' : 'coding') ." abilities.";
  </code></pre>
  
  <p>Which should output the text "This option [enhances / does not enhance] your [gaming / coding] abilities", depending on the variables set.</p>
  
  <p>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.</p>
  
  <p>I would then like to create a html table using only variables to change the base text: </p>
  
  <pre><code>$enhances=1;
  $ability=0;
  echo "
  &lt;tr&gt; 
      &lt;td&gt;&lt;div class=\"factors\"&gt;Enhances = 1&lt;br&gt; Ability = 0&lt;/div&gt;&lt;/td&gt;
      &lt;td&gt;&lt;div class=\"message\"&gt;$base&lt;/div&gt;&lt;/td&gt;
  &lt;/tr&gt;
  ";
  $ability=1;
  $enhances=1;
  echo "  
  &lt;tr&gt; 
      &lt;td&gt;&lt;div class=\"factors\"&gt;Enhances = 1 &lt;br&gt; Ability = 1&lt;/div&gt;&lt;/td&gt;
      &lt;td&gt;&lt;div class=\"message\"&gt;$base&lt;/div&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  ";
  </code></pre>
  
  <p>This how ever outputs something like this: </p>
  
  <pre><code>Enhances = 1
  Ability = 0
  This option does not enhance your coding abilities.
  Enhances = 1 
  Ability = 1
  This option does not enhance your coding abilities.
  </code></pre>
  
  <p>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.</p>
  
  <p>Similar post, but with only one variable inside a variable: <a href="https://stackoverflow.com/questions/11221360/php-evaluating-variable-in-string-and-then-changing-value-of-variable">PHP: Evaluating variable in string, and then changing value of variable</a></p>