Page 1 of 1

Easy way to shorten conditionals?

Posted: Mon Jan 10, 2011 7:00 am
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

Re: Easy way to shorten conditionals?

Posted: Mon Jan 10, 2011 7:03 am
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.

Re: Easy way to shorten conditionals?

Posted: Mon Jan 10, 2011 7:06 am
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.