NYCPHP Meetup

NYPHP.org

[nycphp-talk] switch cases

Ken Robinson kenrbnsn at rbnsn.com
Sat Dec 1 12:47:36 EST 2007


At 12:23 PM 12/1/2007, David Krings wrote:
>Hi!
>
>I make use of a switch statement, but now need to execute the same 
>code of one case for a different case (it is a switch on a file type 
>and some types are to be handled the same). I know how to craft this 
>case using if, but how would I do that with using case within a switch?
>Is it something like this
>switch ($a) {
>         case 'a' or 'b':
>                 // this is for the case that $a is 'a' or 'b'
>         case 'c':
>                 // this is for the case that $a is 'c'
>         default:
>                 // this is for the case that $a is neither 'a', 'b', or 'c'
>}

You would list each case, one after another:

switch ($a) {
        case 'a':
        case 'b':
//
//    stuff for 'a' or 'b'
//
          break;
        case 'c':
//
//      .....
//
             break;
        default:
}

Ken 




More information about the talk mailing list