The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 13 of 13

Thread: <?PHP ?>: If Statements in Switch cases

  1. #1

    <?PHP ?>: If Statements in Switch cases

    Is this actually possible? I thought I saw this before. Not sure if it was real or not. If so, then how does it work?


  2. #2
    case "something":
    if ($true)
    {
    echo('it was true');
    }
    break;

    ... I'm quite confused though what your talking about.

    Join #kirupa | Click the under my Username | CL | Jeff

  3. #3
    Quote Originally Posted by Templarian View Post
    case "something":
    if ($true)
    {
    echo('it was true');
    }
    break;

    ... I'm quite confused though what your talking about.
    Like a switch() having a IF statement in it.


  4. #4
    Like:
    PHP Code:
    switch($a == $b $c $d){

    ?

  5. #5
    Quote Originally Posted by blazes View Post
    Like:
    PHP Code:
    switch($a == $b $c $d){

    ?
    No he means inside each "case" not the condition for the switch itself.
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

  6. #6
    1,839
    posts
    Registered User
    PHP Code:
    switch($myVar){
        case 
    'a'
              if(
    $sessionVar 'joran rules'){
                        echo 
    $sessionvar;
              }
              break;
        case 
    'b':
              if(
    $sessionVar 'joran rules'){
                        echo 
    $sessionvar.",  NOT!!";
              }
              break;
          



  7. #7
    Why are you using switches in the first place?

  8. #8
    1,839
    posts
    Registered User
    switches are better than a buncha ifs(not sure about performance wise, maybe someone else knows, but definatly easier to dealwith...at least imho)...but he probably wants to check some global var from inside..

  9. #9
    According to all my speed tests, switchs are far faster than a bunch of ifs, and the more ifs you'd have, the faster it gets.

  10. #10
    I've read that switches are slower so I never use them. *shrug*

  11. #11
    icio's Avatar
    3,811
    posts
    looks better in lowercase
    Switches might be faster, but they're generally employed be people not-so-in-the-know for things that could be done using completely different methods, faster.

    What are you trying to do with the switch statement, bear?
    "60% of the time it works... every time." -- Paul Rudd as Brian Fantana.

  12. #12
    Quote Originally Posted by icio View Post
    Switches might be faster, but they're generally employed be people not-so-in-the-know for things that could be done using completely different methods, faster.

    What are you trying to do with the switch statement, bear?
    I disagree, the switch construct is a very useful one when employed correctly. It's great to use instead of 5 or more if statements personally.
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

  13. #13
    icio's Avatar
    3,811
    posts
    looks better in lowercase
    I disagree, the switch construct is a very useful one when employed correctly.
    Ie. By people in-the-know. People not-in-the-know tend to use them over more practiced and generally prefered techniques which don't require switches to be used at all. I made no point over their usage with regards to if-statements.

    I thought I was pretty clear on this. Sorry for your confusion.
    "60% of the time it works... every time." -- Paul Rudd as Brian Fantana.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012