homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Else If command
Can this be done?

 10:27 pm on Mar 24, 2003 (gmt 0)


I have a system which requires logging on etc etc.

Each user is assigned one of three levels, 0, 1 or 2

Most functions/pages can be viewed by all, some can only be viewed by 1 and some by 2 etc etc.

To work this, and instead of having different pages for different users etc, I have else and if statements on the page:

if ($level == 1) {
Info for Level 1 users
if ($level == 2) {
Info for Level 2 users

What I now need to be able to do is to have an if statement which can handle level 1 AND 2 users at the same time.

Sort of:
if ($level == 1 OR 2)

Does anybody know how this could be done?

Kindest Regards,



 11:15 pm on Mar 24, 2003 (gmt 0)

I would take a look at switch [php.net]

you can then have drop through cases

case 0:
do stuff;
case 1: //this case will drop through to the next because of the missing break
case 2:
do other stuff;


 11:17 pm on Mar 24, 2003 (gmt 0)

I believe you use the pipe() character for "OR".

if ($level == 1 2)


 11:31 pm on Mar 24, 2003 (gmt 0)

is a bitwise operator [php.net]
is a logical operator [php.net]

*always replace "" with real pipe character


 12:53 am on Mar 25, 2003 (gmt 0)

See How to handle permission levels [webmasterworld.com] in the Bag-O-Tricks for PHP II [webmasterworld.com] for a way to handle permission levels more easily.



 7:32 am on Mar 25, 2003 (gmt 0)

Hi All...Thanks for responding.

This seems the most simplest and easiest way to do what I need to do, and it works fine...Thank You

Very good post that you refer to..unfortunately this little bit was only needed at the last minute :(, and I don't have the time to change all the other parts of the systemto use the method you explained. No doubt it will come in very handy one day ;)

Thanks again,


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved