Jump to content

[SOLVED] Help with IF statement with multiple options


refiking

Recommended Posts

The simple answer to your question would be...

 

<?php

if($month == 1 || $month == 2 || $month == 3 || $month == 4) {
  // Do the dew.
}

?>

 

<?php

if($month < 5) {
  // Do the dew.
}

?>

 

But there are definitely a number of ways to tackle that. Would have to know what you're trying to do to say which would probably be best.

 

<?php
//$month is just a made up variable
if($month = 01){
//do month 01 stuff
}
else if($month = 02){
//do month 02 stuff
}
else if($month = 03){
//do month 03 stuff
}
// ... etc. until you get to month 12 or whatever
?>

 

Or here's another way:

<?php
//$month is just a made up variable
if($month = 01 || $month = 02 || $month = 03){
//do month stuff
}
else if($month = 04 || $month = 05 || $month = 06){
//do month 02 stuff
}
?>

keep in mind they don't have sequential order. Also those double pipes you see ( || ) mean OR

 

 

I see someone beat me to this, I'll post anyway, though.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.