note 102244 deleted from control-structures.switch by danbrown
| From: | danbrown@php.net | Date: | Thu, 03 Feb 2011 18:02:59 +0000 |
| Subject: | note 102244 deleted from control-structures.switch by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176654@lists.php.net to get a copy of this message | ||
Note Submitter: fastballweb
----
theimp at iinet dot net dot au :
How is that mess better than the sane way of doing it?
<?php
function flavor($type = null)
{
$flavors = array('chocolate', 'strawberry', 'vanilla');
if (in_array($type, $flavors)) {
return "Flavor selected: $type";
} else {
return "Flavors available: " . implode(", ", $flavors);
}
}
?>
I'm all for learning the ins and outs of the PHP interpreter, but you're trying to say
that your abuse of the switch syntax will somehow cut down on code maintenance? How can that be,
when your method requires copy-pasting code (always a red flag) and the normal way doesn't?