note 102244 deleted from control-structures.switch by danbrown

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
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?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.