title: In PHP, is conditional variable substitution possible?
body: <p>I was wondering if something like the following would be possible in PHP:</p>
  
  <pre><code>&lt;?php echo "Hello {isset($name) ? $name : 'World'}!\n"; ?&gt;
  </code></pre>
  
  <p>or do I have to do the following?</p>
  
  <pre><code>&lt;?php echo "Hello " . ( isset($name) ? $name : 'World' ) . "!\n"; ?&gt;
  </code></pre>
  
  <p>In general I prefer substitution over concatenation as I find that string concatenation can make strings harder to read by making them overly long.</p>
  
  <p>The context of which is that I'm deciding which option in a select tag should be selected by default based on a database query.</p>
  
  <p>The full context:</p>
  
  <pre><code>&lt;?php   
  echo "
  &lt;form action='add_demographics.php' method='post'&gt;
     &lt;table&gt;
        &lt;input type=hidden name=userId value='{$_SESSION['username']}'/&gt;
        &lt;tr&gt;&lt;td&gt;User ID:&lt;/td&gt;&lt;td&gt;{$_SESSION['username']}&lt;/td&gt;&lt;/tr&gt;";
  
  foreach ($inputLabels as $i =&gt; $value)
  {
      echo "
        &lt;tr&gt;
           &lt;td&gt;{$value['text']}&lt;/td&gt;
           &lt;td&gt;&lt;select name=$i&gt;";
  
      foreach ($value["options"] as $optionName =&gt; $optionValue)
      {
      echo "
              &lt;option value=$optionValue {($result[$i]==$optionValue ? ' selected=true' : '')}&gt;$optionValue&lt;/option&gt;";
      }
      echo "
            &lt;/select&gt;&lt;/td&gt;
        &lt;/tr&gt;";
  }
  
  echo "
        &lt;tr&gt;&lt;td&gt;&lt;input type='submit' name='submit' value='Submit' /&gt;&lt;/td&gt;&lt;/tr&gt;
     &lt;/table&gt;
  &lt;/form&gt;";
  ?&gt;
  </code></pre>