Jump to content

Case Statement


EchoFool

Recommended Posts

Is it possible to do case statements with "ranges"...

 

So say i have the number 100 and the case checked if the number was between 50 and 150 ?

 

Currently i can only see the case statement using precise values... if its not possible is my only other option using if statements?

Link to comment
Share on other sites

Yes, you can use ANY kind of comparison in a CASE statement - you just have to be creative. Remember the case value must match the switch value. So, just use the boolean true for the switch value and the comparisons as the case value

 

Example

switch(true)
{
  case ($num>50 && $num<150):
    //action goes here
  break;

  case ($num>=150 && $num<300):
    //action goes here
  break;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.