Re: Multiple "if()" statements

From: Date: Fri, 30 Jun 2006 14:33:35 +0000
Subject: Re: Multiple "if()" statements
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-238985@lists.php.net to get a copy of this message
On 6/30/06, tedd <tedd@sperling.com> wrote:
At 11:07 PM -0600 6/29/06, John Meyer wrote: Larry Garfield wrote:
switch is fine if your elseif comparisons are equality based. If they're not equality based, then they don't map to switch as well.
Not true. I've come to really appreciate the structure of switches. What helps to "unlock" their power is that you don't *have* to compare your switch() param with your case() params. Building on Paul's good advice of splitting logic from presentation: [code] $display_name = ''; switch('set_display_name') { case($row[1] == 'none'): case($row[1] == $row[2]): $display_name = $row[0] . ' ' . $row[2]; break; default: $display_name = $row[0] . ' (' . $row[1] . ') ' . $row[2]; break; } // now print table, using $display_name [/code] HTH, John W

« previous php.general (#238985) next »