refiking Posted September 17, 2008 Share Posted September 17, 2008 I want to have an if statement that allows this. IF month = 01, 02, 03, or 04 { blah blah How do I code that? Link to comment https://forums.phpfreaks.com/topic/124728-solved-help-with-if-statement-with-multiple-options/ Share on other sites More sharing options...
Caesar Posted September 17, 2008 Share Posted September 17, 2008 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. Link to comment https://forums.phpfreaks.com/topic/124728-solved-help-with-if-statement-with-multiple-options/#findComment-644268 Share on other sites More sharing options...
Goldeneye Posted September 17, 2008 Share Posted September 17, 2008 <?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. Link to comment https://forums.phpfreaks.com/topic/124728-solved-help-with-if-statement-with-multiple-options/#findComment-644269 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.