The 5th Annual China PHP Conference

Voting

Please answer this simple SPAM challenge: three plus five?
(Example: nine)

The Note You're Voting On

jsb17 at cornell dot edu
10 years ago
As an addendum to David's 10-Nov-2005 posting, remember that curly braces literally mean "evaluate what's inside the curly braces" so, you can squeeze the variable variable creation into one line, like this:

<?php
 
${"title_default_" . $title} = "selected";
?>

and then, for example:

<?php
  $title_select
= <<<END
    <select name="title">
      <option>Select</option>
      <option
$title_default_Mr  value="Mr">Mr</option>
      <option
$title_default_Ms  value="Ms">Ms</option>
      <option
$title_default_Mrs value="Mrs">Mrs</option>
      <option
$title_default_Dr  value="Dr">Dr</option>
    </select>
END;
?>

<< Back to user notes page

To Top