note 59837 added to control-structures.alternative-syntax
| From: | rramsey at dracovolans dot com | Date: | Sat, 17 Dec 2005 13:50:43 +0000 |
| Subject: | note 59837 added to control-structures.alternative-syntax | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-100336@lists.php.net to get a copy of this message | ||
Why not do this:
<?
$message = "";
$style = "";
if ($time =="noon")
{
$message = "It's noon.";
$style = "style:\"font-weight:bold;\";
}
else if ($time =="evening")
{
$message = "It's time for bed.";
$style = "style:\"color:blue;\";
}
else if ($time =="morning")
{
$message = "It's time to wake up.";
$style = "style:\"color:green;font-style:italic;\";
}
print "<p $style>$message</p>\n";
?>
Sure, it's an almost absurdly simple example, but the point is to completely separate the
programming from the presentation. This simplifies the html output part of the php code from the
logic part of the code, making both simpler and easier to change as the app changes.
Not that these examples of alternate control structures aren't great and good to know. ;)
----
Manual Page -- http://www.php.net/manual/en/control-structures.alternative-syntax.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59837
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59837&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59837&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59837&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59837&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59837&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59837&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59837&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59837&report=yes
Search -- http://master.php.net/manage/user-notes.php