note 73627 deleted from language.basic-syntax by googleguy
| From: | googleguy@php.net | Date: | Sat, 19 Jan 2013 03:43:40 +0000 |
| Subject: | note 73627 deleted from language.basic-syntax by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-193231@lists.php.net to get a copy of this message | ||
Note Submitter: Geekman at Textbook Torrents dot com
----
Regarding the comment by rosswilliams at advocacytechnologies dot org:
Your suspicion is correct. The following all behave exactly the same:
<?php
// output the answer by escaping
if ($true_or_false) {
?>
<p>The value of $true_or_false is true.</p>
<?php
} else {
?>
<p>The value of $true_or_false is false.</p>
<?php
}
// use echo to do the same thing - more effecient and easier to read in my opinion
if ($true_or_false) {
echo '<p>The value of $true_or_false is true.</p>';
} else {
echo '<p>The value of $true_or_false is false.</p>';
}
// use ? : operators on entire string
echo ($true_or_false) ? '<p>The value of $true_or_false is true.</p>' :
'<p>The value of $true_or_false is false.</p>';
// use ? : operators only on the pertinent bit, to save space
echo '<p>The value of $true_or_false is ' . (($true_or_false) ? 'true' :
'false') . '.</p>';
?>