jaikar Posted September 16, 2007 Share Posted September 16, 2007 Hi .. is there any alternative to the below code?. if($flag == 1 || $flag == 2 || $flag == 3) { do someting } else { do something else } is there anything like $flag == 1 || 2 || 3 ?... will this work ? please advice.. Thanks ~J Link to comment https://forums.phpfreaks.com/topic/69575-solved-is-there-any-alternative-to-this/ Share on other sites More sharing options...
pocobueno1388 Posted September 16, 2007 Share Posted September 16, 2007 Nope, the way you are doing it is the correct way =] This One: <?php if($flag == 1 || $flag == 2 || $flag == 3) { //do someting } else { //do something else } ?> Link to comment https://forums.phpfreaks.com/topic/69575-solved-is-there-any-alternative-to-this/#findComment-349618 Share on other sites More sharing options...
Jessica Posted September 16, 2007 Share Posted September 16, 2007 if it's a lot more than that, make an array and use in_array() Link to comment https://forums.phpfreaks.com/topic/69575-solved-is-there-any-alternative-to-this/#findComment-349625 Share on other sites More sharing options...
rarebit Posted September 16, 2007 Share Posted September 16, 2007 Not really but: if ($x >= 1 && $x <= 3) { } Link to comment https://forums.phpfreaks.com/topic/69575-solved-is-there-any-alternative-to-this/#findComment-349626 Share on other sites More sharing options...
jaikar Posted September 16, 2007 Author Share Posted September 16, 2007 Thankyou for the ideas ! ~J Link to comment https://forums.phpfreaks.com/topic/69575-solved-is-there-any-alternative-to-this/#findComment-349628 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.