galvin Posted November 28, 2008 Share Posted November 28, 2008 I'm just concerned with the syntax for saying "or" multiple times. If I have people logging in to my site that all have different a "userid", what is the proper syntax to say "if a userid equals 2 or 6 or 11 or 17, then do this." I thought it would be... if ($_SESSION["userid"] == 2 || 6 || 11 || 17) { } But that doesn't seem to be working. Do I have to write each one out, as in... if ($_SESSION["userid"] == 2) || ($_SESSION["userid"] == 6) || ($_SESSION["userid"] == 11) || ($_SESSION["userid"] == 17) { } That's fine if I have to write them out like that, but I figured there would be a shorter way to write it. Please confirm either way. Thanks, Greg Link to comment https://forums.phpfreaks.com/topic/134663-solved-simple-question-on-php-syntax/ Share on other sites More sharing options...
.josh Posted November 28, 2008 Share Posted November 28, 2008 $array = array(2,6,11,17); if (in_array($_SESSION['userid'],$array)) { // true } Link to comment https://forums.phpfreaks.com/topic/134663-solved-simple-question-on-php-syntax/#findComment-701168 Share on other sites More sharing options...
.josh Posted November 28, 2008 Share Posted November 28, 2008 or you can use a switch Link to comment https://forums.phpfreaks.com/topic/134663-solved-simple-question-on-php-syntax/#findComment-701169 Share on other sites More sharing options...
galvin Posted November 28, 2008 Author Share Posted November 28, 2008 Great, thank you!!! Link to comment https://forums.phpfreaks.com/topic/134663-solved-simple-question-on-php-syntax/#findComment-701171 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.