SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In switch, can I use > or < comparison ?
    For eg, how could you translate this if/else into switch?

    Code:
    if ($var > $low1 && $var<$high1)
    {doThis();}
    elseif ($var > $low2 && $var<$high2)
    {doThat();}
    else {doDefault();}
    Thanks,
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do you mean like

    $num = 5;


    switch($num) {
    case $num < 4;
    print "The Number is less than 4";
    break;

    case $num > 4;
    print "The Number is greater than 4";
    break;

    case $num > 6;
    print "The Number is greater than 6";
    break;

    case $num > 8;
    print "The Number is greater than 8";
    break;

    }


    Yes but you would have to really plan it out because once a case is matched then it breaks from the switch and if the $num met two cases only the first would get run.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could I combine 2 conditions in one case?
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  4. #4
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect,
    Got it to work with combined conditions.
    Thanks
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy


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
  •