SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast mandi_nole's Avatar
    Join Date
    Jun 2001
    Location
    Orlando, FL
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    multiple values in case statement?

    Is it possible to have multiple values in a case statement (part of a switch)? For instance, in ASP you would simply separate multiple values by a comma:

    Select Case
    Case 1,2,3
    something
    Case 4,5,6
    something else
    End Select

    I've tried this same thing in PHP 4, with no success (generates a syntax error). Is it possible, and if so, what is the proper separator syntax (comma, semicolon, period???)? There isn't any documentation that I can find on switch that shows anything but a single case argument...
    Love ya - mean it!

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    switch ($foo) {
       
       case 
    1:
       case 
    2:
       case 
    3:
          
    // do something
          
    break;

       case 
    4:
       case 
    5:
       case 
    6:
          
    // do something
          
    break;
       
       default:
          
    // do default

    Generally, PHP follows the C langauge's control structures, so if you know or can find out how a control structure works in C then chances are that's how its done in php


Bookmarks

Posting Permissions

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