[PHP] Logic of conditionals and the ( ) operators

2009-12-18 Thread Allen McCabe
In a nutshell:

Will this work?

if ($perm == (11 || 12))


Explanation:

I am laying the groundwork for a photo viewing system with a private and
public mode, and additionally if an admin is logged in, there is an
additional level of permission. I came up with a number system to make it
easier (and is calcualted by a class) so now, instead of checking against
the $mode variable, if the user is logged in, and then what their user level
is if they are logged in, I just check against some numbers (the class
evaluates all those conditions and assigns the appropriate number a single
permission variable, $perm.


Re: [PHP] Logic of conditionals and the ( ) operators

2009-12-18 Thread Ashley Sheridan
On Fri, 2009-12-18 at 10:21 -0800, Allen McCabe wrote:

 In a nutshell:
 
 Will this work?
 
 if ($perm == (11 || 12))
 
 
 Explanation:
 
 I am laying the groundwork for a photo viewing system with a private and
 public mode, and additionally if an admin is logged in, there is an
 additional level of permission. I came up with a number system to make it
 easier (and is calcualted by a class) so now, instead of checking against
 the $mode variable, if the user is logged in, and then what their user level
 is if they are logged in, I just check against some numbers (the class
 evaluates all those conditions and assigns the appropriate number a single
 permission variable, $perm.


That equates to if($perm == true) as 11 in this case translates to true
(being a positive integer) The code never needs to figure out the ||
part, as the first part is true.

I think what you'd want to do is possibly:

if($perm == 11 || $perm == 12)

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Logic of conditionals and the ( ) operators (RESOLVED)

2009-12-18 Thread Allen McCabe
Thank you Ashley, it makes perfect sense. I don't know why I didn't just set
up some tests like Shiplu suggested!

I've rewritten all my code BACK to the correct way. (I thought it looked
cooler, oh well).

On Fri, Dec 18, 2009 at 10:47 AM, Ashley Sheridan
a...@ashleysheridan.co.ukwrote:

   On Fri, 2009-12-18 at 10:21 -0800, Allen McCabe wrote:

 In a nutshell:

 Will this work?

 if ($perm == (11 || 12))


 Explanation:

 I am laying the groundwork for a photo viewing system with a private and
 public mode, and additionally if an admin is logged in, there is an
 additional level of permission. I came up with a number system to make it
 easier (and is calcualted by a class) so now, instead of checking against
 the $mode variable, if the user is logged in, and then what their user level
 is if they are logged in, I just check against some numbers (the class
 evaluates all those conditions and assigns the appropriate number a single
 permission variable, $perm.


 That equates to if($perm == true) as 11 in this case translates to true
 (being a positive integer) The code never needs to figure out the || part,
 as the first part is true.

 I think what you'd want to do is possibly:

 if($perm == 11 || $perm == 12)

   Thanks,
 Ash
 http://www.ashleysheridan.co.uk





Re: [PHP] Logic of conditionals and the ( ) operators

2009-12-18 Thread Jonathan Tapicer
Hi,

Yes, what Ashley said is correct. Also, if you want to avoid writing
$perm several times in the if, or if you have a lot of permissions you
can do:

if (in_array($perm, array(11, 22)))

And you can put in that array all the permissions you need to.

Regards,

Jonathan

On Fri, Dec 18, 2009 at 3:47 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 On Fri, 2009-12-18 at 10:21 -0800, Allen McCabe wrote:

 In a nutshell:

 Will this work?

 if ($perm == (11 || 12))


 Explanation:

 I am laying the groundwork for a photo viewing system with a private and
 public mode, and additionally if an admin is logged in, there is an
 additional level of permission. I came up with a number system to make it
 easier (and is calcualted by a class) so now, instead of checking against
 the $mode variable, if the user is logged in, and then what their user level
 is if they are logged in, I just check against some numbers (the class
 evaluates all those conditions and assigns the appropriate number a single
 permission variable, $perm.


 That equates to if($perm == true) as 11 in this case translates to true
 (being a positive integer) The code never needs to figure out the ||
 part, as the first part is true.

 I think what you'd want to do is possibly:

 if($perm == 11 || $perm == 12)

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php