PDA

View Full Version : Multiple Parameters for Conditionals


inthezone
02-27-2003, 12:12 AM
I am writing a basic PHP conditional script that uses vBulletin's global.php to display different messages for different user levels. I want to have the same message display for those who have userlevels 1 and 3. I know how to write it with elseif syntax, like:


if ($bbuserinfo['usergroupid']==1)
{
echo "You are not logged in, or you have not confirmed your e-mail address.";
}
elseif ($bbuserinfo['usergroupid']==3)
{
echo "You are not logged in, or you have not confirmed your e-mail address.";
}


is there a way to combine the two statements to eliminate the redundancy in that code, so that it will look something like:


//This code leads to a parse error, but I am trying to do something to this effect.


if ($bbuserinfo['usergroupid']==1) or if ($bbuserinfo['usergroupid']==3)
{
echo "You are not logged in, or you have not confirmed your e-mail address.";
}


Edit-accidentally left out a bit of the code.

lynda
02-27-2003, 12:21 AM
You should be able to do something like this without problems:


if ($bbuserinfo['usergroupid']==1 || $bbuserinfo['usergroup']==3)
{
echo "You are not logged in, or you have not confirmed your e-mail address.";
}


The || stands for OR.

Boofo
02-27-2003, 12:21 AM
Will this work?

if ($bbuserinfo['usergroupid']==1 or $bbuserinfo['usergroupid']==3)

inthezone
02-27-2003, 12:25 AM
Both methods work. Thanks for the help

Xenon
02-27-2003, 10:09 AM
yes, but you should prefer the or, its easier to read :)

also this method works and looks much better for more than two groups:

if (in_array($bbuserinfo['usergroupid'], array(1,3)))
{
echo "You are not logged in, or you have not confirmed your e-mail address.";
}

Boofo
02-27-2003, 10:29 AM
I was going to post that but since it was only 2, I went with the "or". ;)

Xenon
02-27-2003, 10:34 AM
*gg*
even when there are just two it's shorter as you can see ;)

and so it's easy to add another group, so why don't just give him the solution for make it easy and fast ;)

Boofo
02-27-2003, 10:47 AM
You're right, I should have gone the other route. I usually use the "or" if it is only 2 though. Habit more than anything, I guess. ;)