Easy way to shorten conditionals?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
billyq
Forum Newbie
Posts: 7
Joined: Mon Jan 10, 2011 6:56 am
Location: Merseyside, UK

Easy way to shorten conditionals?

Post by billyq »

Does anyone know if there's an easy way to shorten conditionals?

For example, is there a way of rewriting this to make it shorter?

Code: Select all

if ($_SESSION['userClassName'] == "admin" || $_SESSION['userClassName'] == "superuser")
I'm guessing that PHP might have a nifty way of returning true if _SESSION['userClassName'] is either 'admin' or 'superuser'.

Thanks
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Easy way to shorten conditionals?

Post by josh »

Well all you need in a conditional is something that returns a boolean. in_array() checks if a given value is in another set of values, and returns true if so, false otherwise.
billyq
Forum Newbie
Posts: 7
Joined: Mon Jan 10, 2011 6:56 am
Location: Merseyside, UK

Re: Easy way to shorten conditionals?

Post by billyq »

josh wrote:Well all you need in a conditional is something that returns a boolean. in_array() checks if a given value is in another set of values, and returns true if so, false otherwise.
Magic -- I knew someone would have a quick way of doing it!

Thanks a lot for your help.
Post Reply