note 57668 deleted from control-structures.switch by nlopess
| From: | nlopess@php.net | Date: | Tue, 11 Oct 2005 08:09:41 +0000 |
| Subject: | note 57668 deleted from control-structures.switch by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-96823@lists.php.net to get a copy of this message | ||
Note Submitter: troll at php dot net
----
<?php
//Depending on Group
switch (TRUE) {
//[snip]
case in_array('rma_rma', $userGroup):
$home = "rma_home.php";
break;
}
?>
--
Folks, these switch(TRUE) statements are totally useless and in many cases incomprehensible to those
of us inheriting projects written by bad coders! That's basically replicating the
functionality of an if..then statement. Observe:
<?php
if ( in_array('rma_rma',$userGroup) ) {
$home="rma_home.php";
}
?>
I've taken essentially a 5 line switch statement and brought it down to a 3-line if statement,
and it's more readable.
Heck, why wouldn't "groupHome" be a seperate variable, or database entry thereby
eliminating that whole statement anyway?