PHP Case Statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

PHP Case Statement

Post by quadoc »

I've the following code, but somehow it doesn't seem to work. Could someone tells me what might be wrong?
Thanks...

Code: Select all

switch (label)

case ("label1" || "label2"):
   $a = 3
   break
But if I use the following then it works

Code: Select all

switch (label)

case "label1"
   $a = 3;
   break
case "label2"
   $a = 3;
   break
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Code: Select all

switch ($label) {
    case 'label1':
    case 'label2':
        $a = 3;
        break;
    default:
        //etc..
}
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

Post by quadoc »

Thanks! That works... :lol:
Post Reply