Re: Multiple "if()" statements

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6/30/06, tedd <tedd@xxxxxxxxxxxx> 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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux