Forum Moderators: coopster

Message Too Old, No Replies

switch statement help

how do i do case ('this') or ('This')

         

KrazyKid

11:00 pm on May 7, 2005 (gmt 0)

10+ Year Member



here's part of my script:

switch ($member)
{
case (('justus') ¦¦ ('Justus')):
echo "bla";
break;

case (('tsavo') ¦¦ ('Tsavo')):
echo "blah";
break;
}

and here's my problem: no matter what $member equals, the first case always gets executed. what am i doing wrong? thanks

Stormfx

11:10 pm on May 7, 2005 (gmt 0)

10+ Year Member



Why not try:

case (strtolower($member)) {
case 'justus':
// blah
case tsvo:
// blah
}

I think your condition has to either be in parenthesis or has to be evaluated prior to the switch.

KrazyKid

11:24 pm on May 7, 2005 (gmt 0)

10+ Year Member



ok, thanks, that worked. but for future reference, say it wasn't just a matter of lower/uppercase, and they were completely different, how would i do it?

oyejorge

11:28 pm on May 7, 2005 (gmt 0)

10+ Year Member



You could do this

switch($member){

case 'justus':
case 'Justus':
...
break;

case 'tsavo':
case 'Tsavo':
...
break;
}

KrazyKid

12:00 am on May 8, 2005 (gmt 0)

10+ Year Member



ok thanks