note 59837 deleted from control-structures.alternative-syntax by mazzanet

From: Date: Sun, 18 Dec 2005 06:42:02 +0000
Subject: note 59837 deleted from control-structures.alternative-syntax by mazzanet
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-100347@lists.php.net to get a copy of this message
Note Submitter: rramsey at dracovolans dot com ---- 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. ;)

« previous php.notes (#100347) next »