Results 1 to 4 of 4

Thread: switch statement [Resolved]

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    switch statement [Resolved]

    can you have multiple values in one case?

    PHP Code:
    case "1,2,3"
    Last edited by ober0330; Feb 27th, 2004 at 08:08 AM.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    try

    PHP Code:
    $chk "blahblah";
    $var "ooga";
    $var2 "booga";
    switch(
    $chk){
      case (
    $var || $var2):
        echo 
    "wiggy waggy woo";
        break;
      default:
        echo 
    "default";

    Like Archer? Check out some Sterling Archer quotes.

  3. #3
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    you can't do that

    working a bit around with it I found out that it is not possible to
    compare the variable with two different values in one step like this
    (system running a w2k server, apache2.0.43 & php430):
    switch ($myvar) {
    case ("foo" || "bar"): //do something
    break;
    case ("other"): //do another thing
    break;
    default:
    }
    rather use:
    switch ($myvar) {
    case ("foo"):
    case ("bar"): //do something
    break;
    case ("other"): //do another thing
    break;
    default:
    }

  4. #4

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Yeah, I actually used that instead. Falling through without breaks seems like the best method.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width